R4nk3d Posted September 15, 2009 Share Posted September 15, 2009 Hi Everyone, I'm making a website and I am trying to create a dynamic nav bar that will include groups(drop-down menu with links) and then regular links that will be displayed as images. I have a column in the mysql table that will determine the priority of the group/link and list them accordingly. I am having trouble reading the groups though. See what you can pull together for me: function ini_NavBar() { $groups = array(); $sql = mysql_query("SELECT * FROM `navigation_groups` WHERE display=1 ORDER BY `priority` ASC"); while($row = mysql_fetch_array($sql)) { $groups[] = array("id" => $row['id'], 'title' => $row['title'], 'priority' => $row['priority'], 'type' => 'group'); } print_r($groups); for($i = 0; $i < sizeof($groups); $i++) { $sql = mysql_query("SELECT * FROM `pages` WHERE group_id='".$groups[$i['id']]."' ORDER BY `priority` ASC"); while($r = mysql_fetch_array($sql)) { $groups[$i['links']] .= $r['id']." "; } } $pages = array(); $sql = mysql_query("SELECT * FROM `pages` WHERE display_link=1 AND group_id IS NULL ORDER BY `priority` ASC"); while($row = mysql_fetch_array($sql)) { $pages[] = array('id' => $row['id'], 'title' => $row['title'], 'priority' => $row['priority'], 'type' => 'page'); } print_r($pages); $priority = array(); $id = array(); $group = array(); foreach($groups as $key => $value) { $priority[$key] = $value['priority']; $id[$key] = $value['id']; $type[$key] = $value["type"]; } foreach($pages as $key => $value) { $priority[$key] = $value['priority']; $id[$key] = $value['id']; $type[$key] = $value["type"]; } array_multisort($priority,SORT_DESC,$id,SORT_ASC,$group,SORT_ASC); return 1; } Thanks! And heres the output: Array ( [0] => Array ( [id] => 1 [title] => Wireless Washtenaw [priority] => 0 [type] => group ) [1] => Array ( [id] => 2 [title] => Support [priority] => 0 [type] => group ) ) Notice: Undefined index: in C:\Inetpub\wwwroot\default\2020comm.com\sources\functions.php on line 13 Notice: Undefined index: in C:\Inetpub\wwwroot\default\2020comm.com\sources\functions.php on line 13 Notice: Undefined index: id in C:\Inetpub\wwwroot\default\2020comm.com\sources\functions.php on line 23 Notice: Undefined index: id in C:\Inetpub\wwwroot\default\2020comm.com\sources\functions.php on line 23 Notice: Undefined index: id in C:\Inetpub\wwwroot\default\2020comm.com\sources\functions.php on line 23 Array ( [0] => Array ( [id] => [title] => Home [priority] => 0 [type] => page ) [1] => Array ( [id] => [title] => Locations [priority] => 4 [type] => page ) [2] => Array ( [id] => [title] => Support & FAQs [priority] => 7 [type] => page ) ) Warning: array_multisort() [function.array-multisort]: Array sizes are inconsistent in C:\Inetpub\wwwroot\default\2020comm.com\sources\functions.php on line 41 Quote Link to comment https://forums.phpfreaks.com/topic/174266-trouble-with-multi_dimensional-arrays/ Share on other sites More sharing options...
DavidAM Posted September 15, 2009 Share Posted September 15, 2009 I'm not real sure, but I think you need to change $groups[$i['id']] to $groups[$i]['id'] and $groups[$i['links']] to $groups[$i]['links'] I don't remember ever seeing multi-dimensions written the way you have it. But the line numbers don't match up. Did you cut out some code or something? Quote Link to comment https://forums.phpfreaks.com/topic/174266-trouble-with-multi_dimensional-arrays/#findComment-918659 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.