6
I’m trying to display a release tag and what seemed to be simple has turned out to be a complication.
Product registration has two fields, data_inicial and data_expiração, initially make a select to show all products, then I am making another select to pick up the products that are with the dates filled in, in case, IS NOT NULL and try to show the tag that is an image, I’ll try not to complicate.
The first select that takes all products according to the defined clauses, the same is so:
mysql_select_db($database_conexao, $conexao);
if ($IdCategoria != 0) {
$query_rsProdutos = "SELECT
produtos_imagem.caminho,
produtos_imagem.caminho_thumbs,
produtos.codigo_iabv,
produtos.nome,
produtos.lancamento,
produtos.id_produto
FROM
categorias
INNER JOIN produtos ON (categorias.id_categoria = produtos.id_categoria)
INNER JOIN produtos_imagem ON (produtos.id_produto = produtos_imagem.id_produto)
WHERE
(produtos.id_produto = produtos_imagem.id_produto) AND
(produtos.id_categoria = '".$IdCategoria."') AND
(produtos.id_idioma = '".$_SESSION['idioma']."') AND
(produtos.`status` = 1)";
} else {
$query_rsProdutos = "SELECT
produtos_imagem.caminho,
produtos_imagem.caminho_thumbs,
produtos.codigo_iabv,
produtos.nome,
produtos.lancamento,
produtos.id_produto
FROM
categorias
INNER JOIN produtos ON (categorias.id_categoria = produtos.id_categoria)
INNER JOIN produtos_imagem ON (produtos.id_produto = produtos_imagem.id_produto)
WHERE
(produtos.id_produto = produtos_imagem.id_produto) AND
(produtos.id_idioma = '".$_SESSION['idioma']."') AND
(produtos.`status` = 1)";
}
$rsProdutos = mysql_query($query_rsProdutos, $conexao) or die(mysql_error());
$row_rsProdutos = mysql_fetch_assoc($rsProdutos);
$totalRows_rsProdutos = mysql_num_rows($rsProdutos);
It shows me all the products, I’m showing them all like this:
<?php do {
mysql_select_db($database_conexao, $conexao);
$query_rsProdutosLanc =
"SELECT
produtos.data_inicial,
produtos.data_expiracao
FROM
produtos
WHERE
(produtos.id_idioma = '".$_SESSION['idioma']."') AND
(produtos.`status` = 1) AND
(produtos.data_inicial IS NOT NULL) AND
(produtos.data_expiracao IS NOT NULL)";
$rsProdutosLanc = mysql_query($query_rsProdutosLanc, $conexao) or die(mysql_error());
$row_rsProdutosLanc = mysql_fetch_assoc($rsProdutosLanc);
$DataInicial = $row_rsProdutosLanc['data_inicial'];
$DataExpiracao = $row_rsProdutosLanc['data_expiracao'];
?>
<div class="col-md-4 col-sm-4"> <a class="shop-item-list" href="detalhes.php?id=<?php echo $row_rsProdutos['id_produto']; ?>">
<figure>
<?php if ($DataInicial <= $DataExpiracao) { ?>
<div class="imagem-mascara"></div>
<?php } ?>
<img src="<?php echo $row_rsProdutos['caminho']; ?>" alt="" />
</figure>
<div class="product-info">
<h2> <span class="product-name"> <span class="bold">CÓD.: </span><?php echo utf8_encode($row_rsProdutos['codigo_iabv']); ?></span> <span class="product-name"><?php echo utf8_encode($row_rsProdutos['nome']); ?></span> </h2>
</div>
</a>
</div>
<?php } while($row_rsProdutos = mysql_fetch_assoc($rsProdutos)); ?>
Inside the loop to show the products I’m making a new select to try to get the dates IS NOT NULL to show the tag launch.
To tag I’m trying to show it like this inside this loop:
<figure>
<?php if ($DataInicial <= $DataExpiracao) { ?>
<div class="imagem-mascara"></div>
<?php } ?>
<img src="<?php echo $row_rsProdutos['caminho']; ?>" alt="" />
</figure>
But the tag is appearing on all products.
Dates are in this format:
data_inicial - 2017-10-01 data_expiracao - 2017-10-31
I even made an attempt at it, but it still didn’t solve;
<?php if (strtotime($DataInicial) <= strtotime($DataExpiracao)) { ?>
<div class="imagem-mascara"></div>
<?php } ?>
gives an example of
$DataInicialand its$DataExpiracao– user60252