Forum Moderators: coopster

Message Too Old, No Replies

Displaying an Array Problem

         

boxfan

6:50 pm on Jan 13, 2006 (gmt 0)

10+ Year Member



Hello,

I have the following function:

function GetList($Value)
{
$order_items_List = Array();
$Database = new DatabaseConnection();
$query = "select * from order_items where (IOrderID = $Value)";
// echo $query;
$Database->Query($query);
for ($i=0; $i < $Database->Rows(); $i++)
{
$order_items = new order_items();
$order_items->Get($Database->Result($i,"IOrderID"));
$order_items_List[] = $order_items;
}
return $order_items_List;
}

The query is correct and returns two distinct records. The problem is when I try to display the results I get two instances of the first record and not both records.

Here's what I'm using to display

$items = new order_items();
$itemslist = $items->GetList(10);
foreach ($itemslist as $items)
{
echo "<tr>";
echo "<td class=\"list\" height=\"25\">".$items->ItemID."</td>";
echo "<td class=\"list\" height=\"25\">".$items->ISKU."</td>";
echo "<td class=\"list\" height=\"25\">".$items->IDescription."<br /></td>";
echo "<td class=\"list\" height=\"25\">&nbsp;</td>";
echo "<td class=\"list\" align=\"right\" height=\"25\">".$items->IPrice."</td>";
echo "<td class=\"list\" align=\"right\" height=\"25\">".$items->IPriceExtended."</td>";
echo "</tr>";
}

Can anyone see where I'm going wrong?

jamie

9:14 am on Jan 14, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



try print_r() on $itemslist

i have a little function in my global includes file which looks like this:

function aDump($array = array()){
echo '<pre>';
print_r($array);
exit;
}

you then call aDump($itemslist); just before you loop through the list and see what it returns - it will show you exactly how the array is structured, which nearly always helps.

if you are still stuck you could post the array structure here.

good luck

boxfan

10:35 pm on Jan 16, 2006 (gmt 0)

10+ Year Member



Perfect. Thanks for the tip!