I have this table in my MySQL database (just a sample)
+----+--------------+---------+--------+-----------+
| id | name | place | number | type |
+----+--------------+---------+--------+-----------+
| 1 | Banana | farm | 100000 | fruit |
| 2 | Apple | park | 100000 | fruit |
| 3 | Eggplant | street | 500 | vegetable |
| 4 | Bitter Gourd | village | 2000 | vegetable |
+----+--------------+---------+--------+-----------+
...
I fetch the data to my webpage using PHP and i want it to show in an ordered list by type like this.
fruit
- banana | farm | 100000
- apple | park | 100000
vegetable
- eggplant | street | 500
- bitter gourd | village | 2000
Can anyone help me with the code, there are many types in my database. I have been able to fetch the data from the database to my webpage as is.
Using this code, but I want to output the data the same way above.
<?php
$result = mysql_query("SELECT * FROM table;");
while($row = mysql_fetch_array($result)) {
$id = $row['id'];
$name = $row['name'];
$type = $row['type'];
echo "
<tr>
<td>$id</td>
<td>$name</td>
<td>$type</td>
</tr>
";
?>