Array display problems

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

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

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>';

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

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()));
}
mysqli_free_result($query);

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;
}
}
unset($node);
unset($list);


Thanks,

hire php developer | hire magento developer

Post Reply
  • Information
  • Who is online

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