Problem with array in shopping cart display script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
mattcooper
Forum Contributor
Posts: 210
Joined: Thu Mar 17, 2005 5:51 am
Location: London, UK

Problem with array in shopping cart display script

Post by mattcooper »

Hello all,

Can anybody see what may be wrong with this script? I need it to do the following:

1> Retrieve a list of items from the database where order_ref=$oid
2> Connect to the database again, accessing another table and retrieving a list of products according to the results of (1)
3> For each of the prod_id records, display summary details about the contents of the cart.

Code: Select all

$oid=$_GET['order_id'];
$sql="SELECT items FROM orders WHERE order_ref='$oid'";
$result=mysql_query($sql);
$i=mysql_fetch_array($result);
foreach($i as $product){
$sql="SELECT * FROM catalogue WHERE prod_id='$product'";
$result=mysql_query($sql);
$num=mysql_num_rows($result);
$display=mysql_fetch_array($result);
foreach($display as $item_row){
echo "$item_row[prod_name], $item_row[short_desc], $item_row[price]<br>";
}
}
}
mysql_close();
This script does everything as planned, but I'm having trouble with the final foreach() function and can't figure out how to display a line of data similar to:

Coffee beans 250g Fresh ground Arabica beans £5.99

I'm getting some strange output with the above code... can anyone shed some light on the problem?

Thanks in advance!

Matt :)
Post Reply