Jump to content

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'];
}
}

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.