# Easy Programming Question.  Arrays specifically

**URL:** <https://boards.straightdope.com/t/easy-programming-question-arrays-specifically/577566>\
**Category:** Factual Questions\
**Created:** [April 7, 2011, 7:17pm UTC](https://boards.straightdope.com/t/easy-programming-question-arrays-specifically/577566 "2011-04-07T19:17:51Z")\
**Posts on this page:** 3\
**Page:** 2

<div class="post-metadata">

**Author:** ![ZipperJJ](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/zipperjj/32/211_2.png) [@ZipperJJ](https://boards.straightdope.com/u/ZipperJJ)\
**Post date:** [April 11, 2011, 12:05am UTC](https://boards.straightdope.com/t/easy-programming-question-arrays-specifically/577566/21 "2011-04-11T00:05:23Z")

</div>

What I usually do in a case like this is to have one MENU table with fields for levels and parents. Then in one query I either get every item, grouped by level and parent. So the dataset returned is like uhm…

```auto

ID Text Level ParentID
1 Animals 0 0
2 Dogs 1 1
3 Beagles 2 2
4 Great Danes 2 2
5 Cats 1 1
6 Calico 2 5
7 Tabby 2 5
8 Cars 0 0
9 American 1 8
10 Ford 2 9
11 Chevy 2 9
12 Japanese 1 8
13 Toyota 2 12
14 Honda 2 12

```

Then I use server-side code to spit out HTML around those items based on their level and parentID, ending up with HTML like

```auto

<ul>
<li>Animals
     <ul><li>Dogs
          <ul><li>Beagles</li>
          <li>Great Danes</li></ul>
      </li>
     <li>Cats
          <ul><li>Calico</li>
          <li>Tabby</li></ul>
     </li></ul>
</li>
<li>Cars
     <ul><li>American
          <ul><li>Ford</li>
          <li>Chevy</li></ul>
     </li>
    <li>Japanese 
         <ul><li>Toyota</li>
         <li>Honda</li></ul>
     </li>
</li>
</ul>

```

Is that the sort of thing you want to do, or do you really need actual lookups because it’s an actual “combination chooser” instead of defined lists?

Perhaps if you Google “php ajax menu” or “php ajax dropdown” that might give you some more insight, too?

---

<div class="post-metadata">

**Author:** ![tim314](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/tim314/32/3468_2.png) [@tim314](https://boards.straightdope.com/u/tim314)\
**Post date:** [April 11, 2011, 12:32am UTC](https://boards.straightdope.com/t/easy-programming-question-arrays-specifically/577566/22 "2011-04-11T00:32:29Z")

</div>

> [@RaftPeople](#):
>
> This part is pretty obvious:  
> B7 02 CC F1 84 29 4F 5D  
> 39 F0 EE 61 78 32 83 D1
> 
> Here’s the tricky part:  
> F7 91 91 A0 0A

I laughed. 🙂

---

<div class="post-metadata">

**Author:** ![treis](https://avatars.discourse-cdn.com/v4/letter/t/bc79bd/32.png) [@treis](https://boards.straightdope.com/u/treis)\
**Post date:** [April 12, 2011, 5:18am UTC](https://boards.straightdope.com/t/easy-programming-question-arrays-specifically/577566/23 "2011-04-12T05:18:38Z")

</div>

> [@ZipperJJ](#):
>
> Is that the sort of thing you want to do, or do you really need actual lookups because it’s an actual “combination chooser” instead of defined lists?
> 
> Perhaps if you Google “php ajax menu” or “php ajax dropdown” that might give you some more insight, too?

I found something through googling that hands off a PHP array to Javascript using, as far as I can figure, magic. Basically what I have is two selection panes with a 3rd pane showing a list. For example, the left pane would be:

Mammals / Dogs, Cats  
Fish / Trout Tuna

The middle pane would be:

Action / Playing, Eating

The right pane would then display links according to the selection. The links then would open the corresponding picture in the rest of the window.

I’ve got it working now though, so thanks for everyone’s help.

[Previous page](https://boards.straightdope.com/t/easy-programming-question-arrays-specifically/577566.md?page=1)
