Hi guys,
I’m just started using php + sql and I really have a problem.
I’ve written a piece of code which should display some products with correlating images and description (out of a database), corresponding to ONE product category.
This is my code:
[code][php]<?php
$cat=2;
$limit=20;
$i=2;
while($i<="$limit"){
$res=mysql_query(“select * from testdb WHERE id=$i AND cat=$cat”) or die(mysql_error());
$row=mysql_fetch_array($res);
$prijs=$row[“prijs”];
$descr=$row[“descript”];
$naam=$row[“naam”];
$prodnr=$row[“id”];
$i++;
echo ‘
echo’
’;echo"$descr";echo’
Prijs:’;echo’ €’;echo"$prijs";echo’ Productnummer: ‘; echo"$prodnr";echo’
}
?>[/php][/code]
Problem is: There are gaps between the list of products shown. The gap is caused by the fact that for a certain $i value there is no corresponding $prodnr (since there are a few gaps in my db) or the fact that the product with that $i value as id doesn’t belong to the chosen category. How can I make the code so that it only displays products corresponding with the chosen category.
Thanks in advance!!!