Array display problems

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Post Reply
User avatar
php-forum GURU
php-forum GURU
Posts: 2192
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: Array display problems

Post by egami » Thu Oct 25, 2012 7:57 am

before you do any of that..
make sure that the array looks like you want it to look...

echo '<pre>'; print_r($data); echo '</pre>';

New php-forum User
New php-forum User
Posts: 20
Joined: Fri Oct 19, 2012 4:32 am
Location: India

Re: Array display problems

Post by jinijames » Mon Oct 29, 2012 3:23 am

$list = array();
$cat = array();
$query = mysqli_query($dbc,"SELECT id, parent_id, category FROM categories ORDER BY parent_id, category LIKE category ASC");
while($row = mysqli_fetch_assoc($query)){
$list[$row['id']] = array_merge($row, array('children' => array()));

foreach($list as $nodeId => &$node) {
if(!$node['parent_id'] || !array_key_exists($node['parent_id'], $list)){
$cat[] = &$node;
} else {
$list[$node['parent_id']]['children'][] = &$node;


hire php developer | hire magento developer

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 3 guests