Hi murphdev,
In order to try and help you, I've tweaked (!) your code to make it readable (to me). Hope you're not offended.
Seems to me that you're trying to write 'minimal' code for some reason. Don't bother with that ... much, much better to write everything out in full, especially if you're a noob.
You'll give yourself a chance to see how to adapt stuff later, without having to 'unpack' the logic first. I know a lot of coders will go your way, but that's because they absolutely know what they're doing, and don't have to 'unpack'.
So, here's a copy of your code ... I may have a made a typo or two, but I can't test it without access to your database!!
<?php
$q1 = "
SELECT *
FROM class_catalog, class_categories
WHERE class_catalog.CategoryID = class_categories.CategoryID
AND class_catalog.FeaturedStatus = '1'
ORDER BY rand()
LIMIT 0, 2
";
$r1 = @mysql_query($q1) or die(mysql_error());
if(mysql_num_rows($r1) > 0){
$FeaturedAds .= '
<table align="center" width="431">
<tr>
<td colspan="2" align="center" valign="top" class="thead" align="center">Featured Ads</td>
</tr>
<tr>';
$al = 0; // Why not just declare it here and give it a comment
while($a1 = mysql_fetch_array($r1)){
$al++;
if($al == 1){
$align = 'align="left"';
} elseif($al == 2){
$align = 'align="center"';
} else {
$align = 'align="right"';
}
$FeaturedAds .= '
<td width="216" '.$align.'>';
$FeaturedAds .= '
<table width="200" cellspacing="0" border="1" bordercolor="#DCDCDC" rules="rows">
<tr>';
if(!empty($a1['images'])){
$ShowImage = explode('|', $a1['images']);
$FeaturedAds .= '
<td width="120" height="96" align="center" valign="top"><img src="images/'.$ShowImage[0].'" width="120" height="96"></td>
<td width="120" height="96" valign="top"><a class="BlackLink" href="info.php?id='.$a1['ProductID'].'">'.$a1['ProductName'].'</a></td>
</tr>';
} else {
$FeaturedAds .= '
<td width="200" height="100" align="left" valign="top"><a class="BlackLink" href="info.php?id='.$a1['ProductID'].'">'.$a1['ProductName'].'</a></td>
</tr>';
}
$FeaturedAds .= '
</table>
</td>';
$fa++;
}
for($fe = 1; $fe <= (2 - $fa); $fe++){
$FeaturedAds .= '
<td width="200"> </td>';
}
$FeaturedAds .= '
</tr>
<tr>
<td colspan="2" align="center" valign="top" height="5"></td>
</tr>
</table>';
}
?>
Notice a couple of things ...
1) I use single quotes for ALL strings and DON'T embed variables. This, for me, is an absolute no-no.
2) Layout the HTML without \n and \t. Note that using single-quoted strings still allows you to do it my way, but won't allow you to use \n or \t which need to be embedded in double-quoted strings.
3) Always put quotes around array keys
Good: $a1['ProductID']
Bad:$a1[ProductID]
4) Don't put quotes around numeric variables
Good: if($al == 1)
Bad: if($al == '1')
5) Although HTML doesn't care at the moment if you don't put double-quotes around attribute values, it is becoming standard practise. For XHTML it is absolutely required.
Good: <table align="center" width="431">
Bad: <table align=center width=431>
6) Comment your code!!!!
Hope that helps ... maybe you can see what to do now ... come back if not.
Paul. 🙂