Multiple Arrays (mySql and PHP)

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
spib
Forum Newbie
Posts: 9
Joined: Wed Jul 09, 2003 2:09 am

Multiple Arrays (mySql and PHP)

Post by spib »

Hey Guys,

I have two db tables. The first is a list of catagories, the second is a list of items each of which has a catagory id. What I want to do is display the data as follows:-

Cat 1
Item 1
Item 2

Cat 2
Item 1
Item 2

Because I am using Smarty, what I want to do is get the data into a series of arrays which I can then traverse in my page display code. What would be the best way to do this? My thoughts are to first grab the list of catagories into one array, then loop through this array selecting the items for each catagory into a series of other arrays with the catagory name prepended to the array name.

Any help which you can give would be much appreciated.
jmarcv
Forum Contributor
Posts: 131
Joined: Tue Jul 29, 2003 7:17 pm
Location: Colorado

Post by jmarcv »

thats one way, the other is:
$data[1]['cat']=$cat1
$data[1]['item1']=$item1
$data[1]['item2']=$cat2
Post Reply