Hello Everyone
I am making a script that generates 10 random links from a db, I want them to have a alternating row colour but I can't seem to get it right.
Look at this:
Everytime it just colours a randome row.
How can I fix that?
I am making a script that generates 10 random links from a db, I want them to have a alternating row colour but I can't seem to get it right.
Look at this:
PHP:
<?php
include 'config.php';
mysql_connect("$host", "$user", "$pass") or die(mysql_error());
mysql_select_db("$dbname") or die(mysql_error());
// lets check to see if we have enough
$checkaff = mysql_query("SELECT * FROM links");
$aff_exist = mysql_num_rows($checkaff);
$maximage = 10;
$halfmaximage = floor($maximage/2);
if($aff_exist >= $maximage){
$query = "SELECT * FROM links";
$result = mysql_query($query) or die(mysql_error());
$i = 0;
while($row = mysql_fetch_array($result)){
$array['text'][$i] = $row['text'];
$array['link'][$i] = $row['link'];
$array['showing'][] = 0;
$i++;
}
echo "<table width='100%' border='0' cellspacing='2' cellpadding='0'>";
$ii = 0;
while($showing < $halfmaximage){
$ii++;
if($ii % 2){
$col = "#F4F4F4";
}else{
$col = "";
}
$randnum = rand(0,$i-1);
if($array['showing'][$randnum] == 0){
echo "<tr>
<td width='75%' bgcolor='$col'><a href='".$array['link'][$randnum]."'>".$array['text'][$randnum]."</a></td>
</tr>";
$array['showing'][$randnum] = 1;
$showing++;
}
}
while($showing2 < $halfmaximage){
if($ii % 2){
$col = "#F4F4F4";
}else{
$col = "";
}
$ii++;
$randnum = rand(0,$i-1);
if($array['showing'][$randnum] == 0){
echo "<tr>
<td width='75%' bgcolor='$col'><a href='".$array['link'][$randnum]."'>".$array['text'][$randnum]."</a></td>
</tr>";
$array['showing'][$randnum] = 1;
$showing2++;
}
}
}
?>
Everytime it just colours a randome row.
How can I fix that?








