Jump to content

Creating a Multi-Dimensional Array from DB


maxudaskin

Recommended Posts

Hi guys,

I'm still stuck on making this multi-level drop down menu, so I figure that I'll listen to how you guys would do it. I don't necessarily need any code, but just ideas on how to code it.

 

Basically, I need it to store each item in a database.

It needs to:

  • be accessed, processed, and formatted with PHP
  • end up returning either a multi-dimensional array, or the raw HTML. Examples:

<?php
array(
  array(
    'label'=>'Test',
    'link'=>'index.php?r=test',
    'sort'=>0,
    'children'=>array(--blah blah blah--)
  ),
  array(--blah blah blah--)
);

<div id="menu">
<ul>
<li><a href="index.php?r=test"><h2>Test</h2></a>
<ul>
<li><a href="blah">Blah</a>
<ul>
<li><a href="blah">Blah</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>


 

That's pretty much it. If you have any ideas or suggestions, please feel free to help me out. Thank you guys!

Link to comment
Share on other sites

 

Doesn't quite help. I understand the concept of multi-dimensional arrays. I'm trying to get the information from my database (effectively a two dimension array (Dim1: Row, Dim2: columns) into a variable dimension array (Items and children [and children's children, ect]).

Link to comment
Share on other sites

 

I don't think you quite understand what I'm trying to do.

 

The array can have as many levels as the user wants it to.

The database has all of the items as a separate row.

If an item is a child of another item, it must be places as a sub array to that item. If there is a child to that sub-array, it must be placed as a sub-array to the sub-array (and so on).

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.