Hello everyone, I'm new to the forum, hopping to find some help.
I'm trying to build a multidimensional array base on a single array... please let me explain.
I have a very basic query as follow.
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query
->select('o.*, u.*, i.*')
->from($db->quoteName('#__redshop_orders', 'o'))
->join('LEFT', $db->quoteName('#__redshop_users_info', 'u').' ON (' . $db->quoteName('u.users_info_id') .' = '. $db->quoteName('o.user_info_id').')')
->join('INNER', $db->quoteName('#__redshop_order_item', 'i') . ' ON (' . $db->quoteName('i.order_id') . ' = ' . $db->quoteName('o.order_id') . ')')
->where($db->quoteName('o.order_number') . ' LIKE '. $db->quote($o_id) .'');
$db->setQuery($query);
$results = $db->loadObjectList();
that will output a single $key per order, say the user has 3 orders it will display
array (
[0] => array ( 'id 1', 'data42')
[1] => array ( 'id 1', 'data26')
[2] => array ( 'id 1', 'data27')
)
the idea is to make a single multidimensional array as follow
array (
[id1] => array (
[user 1] => array (
[order 1] => ( array => [item 1] => 2, [item 2] => 3 )
)
)
)
in other words...
[user 1]
[order id 1]
[items 1]
[items 2]
[items 3]
[order id 2]
[items 15]
[items 25]
[items 33]
[user 2]
[order id 46]
[items 1]
[items 2]
[items 3]
[order id 25]
[items 15]
[items 25]
[items 33]
that type of array is what I'm looking for, for I'm having a hard time to build that array...
Now, that query display all the information that I want just not the way I need
I also made 3 other queries 1 for the user, 1 for the orders and 1 for the items, but I don't see how to put it together...
the ID's that can be use to relate one another are
order_id which is in the users table user_id which is in the orders table and item_id which is in the orders table...
I was using this foreach to put them together but is not working....
$user = array();
$order = array();
$items = array();
foreach ($results as $user) {
$id = $user->order_id;
$user->orders = array();
$order[$id] = $user;
if ($user->order_id == 0) {
$user[$id] = & $orders[$id];
}
foreach ($order as $id => & $node) {
if (isset($order[$node->order_id])) {
$order[$node->order_id]->children[$id] = $node;
}
}
}
print_r($user);
but is not working...
and here is the array that I need to work with as an example...
Array in next post ...
so thats what my query outputs....
Thank you for taking the time...