Separating MySQL SELECT statement based on data in a column
Posted
by NightMICU
on Stack Overflow
See other posts from Stack Overflow
or by NightMICU
Published on 2010-05-02T19:06:56Z
Indexed on
2010/05/02
19:18 UTC
Read the original article
Hit count: 159
Hi everyone,
I need to retrieve data (vehicle details, in this case) from a MySQL table tabled and then loop through the results to generate separate lists for each category of vehicle. Is there a simple way to do this without having to have a SELECT statement for each type of vehicle?
If I were just doing this for one category, I would use the following:
<?php
$sql = "SELECT * FROM apparatus WHERE vehicleType = 'Support';
$getSQL = mysql_query($sql);
?>
<ul>
<?php while ($vehicleData = mysql_fetch_assoc($getSQL)) {?>
<li><?php echo $vehicleData['name'];?></li>
<?php } ?>
</ul>
..etc. Need to do this for four different types of vehicles.
Thanks!
© Stack Overflow or respective owner