Need help to print an array to a html table
Posted: Fri Apr 16, 2010 9:22 pm
Hi all, I need to convert an array to a table (just for trying to learn a little bit more about PHP programming)
I thought it could be a good idea to print a simple array with animals and then printing them into a html table ordering them by family name.
If I want to print an array like this:
-----------------------------------------------------------------------------------
| Equidae | Canis lupus familiaris | Psittacidae
=====================================================
| Some image | Some image | Some image
=====================================================
| Hipparion | Shi tzu | Lovebird
------------------------------------------------------------------------------------
| Mesohippus | German Collie | Blue-and-gold Macaw
------------------------------------------------------------------------------------
| Hyracotherium | Doberman Pinscher | Scarlet Macaw
-----------------------------------------------------------------------------------
| (Empty) | French Mastiff | (Empty)
----------------------------------------------------------------------------------
This is where I arrived so far...
Thanks in advance.
Regards.
StRoYeR
I thought it could be a good idea to print a simple array with animals and then printing them into a html table ordering them by family name.
If I want to print an array like this:
Code: Select all
<?
$Categories = array("Equidae", "Canis lupus familiaris", "Psittacidae");
//How do I store here the names of the animals?
?>| Equidae | Canis lupus familiaris | Psittacidae
=====================================================
| Some image | Some image | Some image
=====================================================
| Hipparion | Shi tzu | Lovebird
------------------------------------------------------------------------------------
| Mesohippus | German Collie | Blue-and-gold Macaw
------------------------------------------------------------------------------------
| Hyracotherium | Doberman Pinscher | Scarlet Macaw
-----------------------------------------------------------------------------------
| (Empty) | French Mastiff | (Empty)
----------------------------------------------------------------------------------
This is where I arrived so far...
Code: Select all
<table>
<tr>
<?
foreach ($Categories as $Category) {
echo " <th>".$Category."</th>\n";
}
?>
</tr>
<tr>
<?
//Here I want to display, for example, an image
foreach ($ImgCategories as $ImgCategory) {
echo ' <td><img src="'.$ImgCategory.'" width="50px" height="50px" /></td>'."\n";
}
?>
</tr>
//I think I should use another "foreach" to display the names of the animals... How do I implement it?
Regards.
StRoYeR