Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

PHP Array Help

$
0
0

Hello Guys, I have a database that is set up something like this:

 

Name                Type_a             Type_b

 

3 series               Car                  BMW

1 series               Car                  BMW

A class                Car                  Merc

C class                Car                  Merc

500                      Motorbike       XYZ

600                      Motorbike       XYZ

 

I want to pull this info out of my database and display it like this:

 

 

Cars:

          BMW:

                        1 Series

                        3 Series

 

          Merc      A Class

          Merc      C Class

 

Motorbikes:

      

          XYZ:

                  500

                  600

 

So far I have this:

$result = mysql_query("SELECT * FROM Cars")or die(mysql_error());


while ($row = mysql_fetch_array($result)) 
{
// we get all of the items in this project and put them into a 3 part Array....
$assets= array('Name' => $row['Name], type_a' => $row['Type_A'], 'Type_B' => $row['Type_B']);
}

print_r($assets);

Now this works fine, I end up with a 3 part array containing all of the information I need. The part I am struggling with, is how to get the information back out of the array in a way I can deal with, to produce the above example. Any help?

 

Thanks guys!


Viewing all articles
Browse latest Browse all 13200

Trending Articles