Foreach Question

I have a database that displays vehicles in a different HTML table based on their vehicle make(e.g. Ford, Chevy). I would like to have the same make’s in the same HTML table. For example, if I have three vehicles, two Fords and one Chevy, I would like to have the two Ford’s in the same HTML table but in a different “

” and then have the Chevy in a different HTML table.

Here is my current code:
[php]

<?php while($row1 = mysql_fetch_array($result)) { ?>
<?php echo $row1['Make']; ?>
Photo Year-Make-Model-Series Exterior Color Mileage Price
/<?php echo $row1['Img1']; ?>" width="150" height="112" border="0"> <?php echo $row1['Year'] . " " . $row1['Make'] . " " . $row1['Model'] . " " . $row1['Series']; ?> <?php echo $row1['Color']; ?> <?php echo $row1['Mileage']; ?> <?php echo $row1['Price']; ?>
<?php } ?> [/php]

I don’t know if you are looking this,

try to put “ORDER BY Make ASC” in SELECT sentence.

Thanks for the quick reply Kikesv!

I would like to put vehicles of the same make in the same table but in a different

With the order that i tell you in select.

Try :
[php]

<?php $datBefore=''; while($row1 = mysql_fetch_array($result)){ if($datBefore!=$row1['Make']){ if($datBefore!=''){ echo ""; } $datBefore=$row1['Make'] ?>
         <table width="1000" align="center">
               <tr>
                    <td><span class="make"><?php echo $row1['Make']; ?></span></td>
              </tr>
         </table>
         <table class="main" width="1000" align="center">
                <tr>
                     <th width="150">Photo</th>
                     <th>Year-Make-Model-Series</th>
                     <th>Exterior Color</th>
                     <th>Mileage</th>
                    <th>Price</th>
                </tr>
<?php } ?>
                <tr>
                       <td align="center" width="150"><a href="/details.php?vid=<?php echo $row1['VID']; ?>"><img src="/img/<?php echo $row1['Category'] . "/" . $row1['Year'] . "_" . $row1['Make'] . "_" . $row1['VID']; ?>/<?php echo $row1['Img1']; ?>" width="150" height="112" border="0"></a></td>
                      <td align="center"><a href="/details.php?vid=<?php echo $row1['VID']; ?>"><?php echo $row1['Year'] . " " . $row1['Make'] . " " . $row1['Model'] . " " . $row1['Series']; ?></a></td>
                        <td align="center"><?php echo $row1['Color']; ?></td>
                        <td align="center"><?php echo $row1['Mileage']; ?></td>
                        <td align="center"><?php echo $row1['Price']; ?></td>
                </tr>
<?php } echo""; ?>

[/php]

Thank your very much! That helps and it finally works! :slight_smile:

-Josh

Sponsor our Newsletter | Privacy Policy | Terms of Service