Hey.
I wrote this code so long ago and just started working with it again and found some bugs. I was hoping someone could help me out with this logic. My PHP is pretty rust at the moment.
I have a MySQL table that contains an inventory of products. There is a column called 'featured', and if under that column the record has a value of 'y' (short for yes), then I want it to display on the homepage as a featured item.
The problem I'm running into is this:
There can be a total of 6 featured items listed on the home page at a time (I've set a lock so there won't ever be more than 6 records with featured equaling y...that's not the problem). The problem is there could be 1 item featured, there could be 4, or any other amount of items could be featured as long as it's no more than 6. I just can't quite structure my loop so that no matter how many items are featured, it will create a table with no problems.
The table is 390 pixels wide, and has 3 columns of 130 pixels. Here's some of the code
$query = mysql_query("SELECT id, year, make, model, picture FROM $table WHERE featured='y'");
$count = mysql_num_rows($query);
if($count >= 1) {
while($row = mysql_fetch_assoc($query)) {
$img[] = $row["picture"];
$id[] = $row["id"];
$year[] = substr($row["year"], 2, 2);
$make[] = $row["make"];
$model[] = $row["model"];
}
?>
<center>
<table width="390" cellspacing="5">
<tr>
<td colspan="3"><center><b><font color="<?= $ftrd_color ?>">FEATURED VEHICLES</font></b></center></td>
</tr>
<tr>
<td width="130" align="center" valign="top">
<font size="1"><b><?= $year["0"] . " " . $make["0"] . " " . $model["0"] ?></b>
<?
if (($img["0"]) && ($img["0"] != "noimage.gif")) {
echo "<br><img src=\"" . $vehicles_dir . "/" . $img["0"] . "\" width=\"130\" height=\"98\" border=1 class=border>\n";
} else {
echo "<br><img src=\"images/noimage2.jpg\" width=\"130\" height=\"98\" border=1 class=border>\n";
}
?>
<a href="?p=specs&id=<?= $id["0"] ?>" class="featured">Details ยป</a>
</td>
<td width="130" align="center" valign="top"></td></tr></table>
<? if ($count > 1) { ?>
//process basically repeats
I'm just having trouble with this and know it's something extremely simple.
Thanks,
Cgraz