Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

db pointer. move down a row

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Basically this query is looping over all items in basket for an order. But instead of returning 1st item, 2nd item, 3rd item in basket like it is suppost to, it will only bring back item 1 for as many times as there are items in the basket. I need to tell the db to point to the next row in the loop to fix the problem, but I not sure how to do this. Any help or suggestions would really cure my headache, thanks.

$query = "select * from order_items where
orderid = '$orderid'";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);

for ($j=0; $j < $num_results; $j++){
$query = &quot;select * from order_items where
orderid = '$orderid'&quot;;
$result = mysql_query($query);
$row = mysql_fetch_array($result);

echo stripslashes($row[&quot;itemNum&quot;]);
echo stripslashes($row[&quot;item&quot;]);
echo stripslashes($row[&quot;quantity&quot;]);
}

The loop does work the correct amount of times but only returns the first item in basket. I need it to return each item in basket. How do you tell mysql to point to the next db row? Any suggestions would really be appreciated.
 
hello
try this



$query = &quot;select * from order_items where
orderid = '$orderid'&quot;;
$result = mysql_query($query);

while ($row=mysql_fetch_array($result)) {

echo stripslashes($row[&quot;itemNum&quot;]);
echo stripslashes($row[&quot;item&quot;]);
echo stripslashes($row[&quot;quantity&quot;]);

}



spookie





 
The while loop did not shut off because it was stuck on only the first row of the results. Eventually timed out it desplayed many rows of only first item. Do you now how to tell it to move to the next row? Thanks for you suggestion.
 
I might have wrote this question a little bit confusing, sorry about that. I was not refering to the var $row in the code, I ment db row. The results will echo out itemNum, item, and quantity but yelds the same info every time it loops.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top