Jump to content

Simple Select from only returning one row


HDFilmMaker2112

Recommended Posts

The following code is returning only one row, when  I know for a fact there are two entries with same product_category in the database. Maybe I'm just missing something blatantly obvious, but I'm not seeing an error in the code.

 

if(isset($_GET['cat'])){
$cat=$_GET['cat'];
$sql30="SELECT * FROM $tbl_name WHERE product_category='$cat'";
$result30=mysql_query($sql30);
while($row30=mysql_fetch_array($result30)){
$content=$row30['product_category'];
}
}

Here's my table:

 

product_id | product_name | product_category | product_tag | product_link | product_price

2 | test | test | test | test | 1

3 | test2 | test2 | test2 | test2 | 2

4 | test2 | test | test | test | 12

 

EDIT:

Just realized my issue, I needed to concatenate  the $content variable because it's looping... it was just taking the last entry because it kept overwriting the $content variable from the last loop.

code is now:

if(isset($_GET['cat'])){
$cat=$_GET['cat'];
$sql30="SELECT * FROM $tbl_name WHERE product_category='$cat'";
$result30=mysql_query($sql30);
while($row30=mysql_fetch_array($result30)){
$content.=$row30['product_category'];
}
}

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.