My PHP skills are self-taught and this is my first real script so the solution is probably pretty simple. Please forgive me.
I am trying to insert ad code into a glossary that is stored in a MySQL database. Just to make things fun, the table alternates background colors based on code from this page.
The code seems to have some logic problems as it currently alternates glossary terms with ad code, but all the glossary terms are appearing correctly and the background colors are alternating as I would like.
PHP Code:
$query = "SELECT term, definition FROM glossary ORDER BY term";
$result = mysql_query($query);
$i = 0;
$adcount = 0;
print "<table cellspacing='0' cellpadding='4'>
<col width='148' />
<col width='476' />
<tr bgcolor='#F4EFE8' height='12'>
<td width='148' height='12'>Term</td>
<td width='476'>Definition</td>
</tr>";
while(($row = mysql_fetch_row($result)) !== false) {
$i++;
$adcount++;
print "<tr class=\"d".($i & 1)."\">"; //alternates css style
print "<td>".$row[0]."</td>";
print "<td>".$row[1]."</td>";
print "<td>".$adcount."</td>"; //for debugging
print "</tr>\n";
if ($adcount == 5|11|17) //show ad after the 5th, 11th, and 17th rows
{
$i++;
$adcount++;
print " <tr class=\"d".($i & 1)."\">";
print " <td></td><td>adcode goes here</td>";
print "<td>".$adcount."</td>"; //for debugging
print "</tr>\n";
}
}
mysql_free_result($result);
print "</table>";
I appreciate any help.
Damon
|