Jump to content

Trouble With Multi_Dimensional Arrays


R4nk3d

Recommended Posts

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.