Page 1 of 1

Problem with array in shopping cart display script

Posted: Wed Mar 08, 2006 3:03 pm
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 :)