Adding database results to array
Posted
by Jason
on Stack Overflow
See other posts from Stack Overflow
or by Jason
Published on 2010-03-26T01:52:29Z
Indexed on
2010/03/26
2:03 UTC
Read the original article
Hit count: 408
Hi all,
I am having a mental blank here and cannot for the life of me figure out a solution.
My scenario is that I am programming in PHP and MySQL. I have a database table returning the results for a specific orderid. The query can return a maximum of 4 rows per order and a minimum of 1 row.
Here is an image of how I want to return the results.
I have all the orderdetails (Name, address) ect stored in a table named "orders". I have all the packages for that order stored in a table named "packages".
What I need to do is using a loop I need to have access to each specific element of the database results (IE package1, itemstype1, package2, itemtype2) ect
I am using a query like this to try and get hold of just the "number of items:
$sql = "SELECT * FROM bookings_onetime_packages WHERE orderid = '".$orderid."' ORDER BY packageid DESC"; $total = $db->database_num_rows($db->database_query($sql));
$query = $db->database_query($sql);
$noitems = ''; while($info = $db->database_fetch_assoc($query)){ $numberitems = $info['numberofitems'];
for($i=0; $i
$noitems .= $numberitems[$i];
}
} print $noitems;
I need to have access to each specific element because I them need to create fill out a pdf template using "fpdf".
I hope this makes sense. Any direction would be greatly appreciated.
© Stack Overflow or respective owner