I'm doing a webpage of products that are inside each category. What i want is when i click the category it loads up in a different page all the products of that category.
I hope you understand what i mean.
The trouble is, i cant pass the category field from one file to another in order to load all the products from the category i selected.
Here is the code of the category page:
$sql="SELECT * FROM $tbl_name ORDER BY nome_cat ASC";
// ORDER BY id DESC is order result by descending
$result=mysql_query($sql);
?>
<br>
<table width="500" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td width="8%" align="center" bgcolor="#214e00"><strong><font color="white"></strong></td>
<td width="55%" align="center" bgcolor="#214e00"><strong><font color="white">Categorias</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){ // Start looping table row
?>
<tr>
<td bgcolor="#FFFFFF"><a href="view_cat.php?id=<?php echo $rows['id_cat']; ?>"> <img src="img/categorias/<?php echo $rows['id_cat'];?>.jpg" width="50" height="50"></a><BR></td>
<td bgcolor="#FFFFFF"><a href="view_cat.php?id=<?php echo $rows['id_cat']; ?>"> <?php echo $rows['nome_cat']; ?></a><BR></td>
</tr>
<?php
// Exit looping and close connection
}
mysql_close();
?>
<tr>
<td colspan="5" align="right" bgcolor="#c1f55c"></td>
</tr>
</table>
And here is the page where it is supposed to appear the products from the category selected:
$sql="SELECT * FROM $tbl_name WHERE cat="here is my doubt" ORDER BY nome ASC";
// ORDER BY id DESC is order result by descending
$result=mysql_query($sql);
?>
<br>
<table width="700" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td width="6%" align="center" bgcolor="#214e00"><strong><font color="white">#</strong></td>
<td width="18%" align="center" bgcolor="#214e00"><strong> <font color="white">Referência</strong></td>
<td width="8%" align="center" bgcolor="#214e00"><strong><font color="white">Foto</strong></td>
<td width="55%" align="center" bgcolor="#214e00"><strong><font color="white">Produto</strong></td>
<td width="13%" align="center" bgcolor="#214e00"><strong><font color="white">Data/Hora</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){ // Start looping table row
?>
<tr>
<td bgcolor="#FFFFFF" align="center"><?php echo $rows['id']; ?></td>
<td align="center" bgcolor="#FFFFFF"><?php echo $rows['ref']; ?></td>
<td bgcolor="#FFFFFF"><a href="ver_produtos.php?id=<?php echo $rows['id']; ?>"> <img src="img/produtos/<?php echo $rows['id'];?>.jpg" width="50" height="50"></a><BR></td>
<td bgcolor="#FFFFFF"><a href="ver_produtos.php?id=<?php echo $rows['id']; ?>"><?php echo $rows['nome']; ?></a><BR></td>
<td align="center" bgcolor="#FFFFFF"><?php echo $rows['datetime']; ?></td>
</tr>
<?php
// Exit looping and close connection
}
mysql_close();
?>