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!

 

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]).

 

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).

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.