Unstoppable Domains

Alternating Row colours

Spaceship Spaceship
Watch

asgsoft

VIP Member
Impact
9
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:

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?
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
PHP:
$ii = 0;
while($showing < $halfmaximage){
  if($ii==0){
    $col = "#F4F4F4"; $ii++;
  } else {
    $col = ""; $ii--;
  }
 
0
•••
Just editing Jim's code:

PHP:
$ii = 1;
while($showing < $halfmaximage){
  if($ii % 2)
    $col = "#F4F4F4"; 
  else
    $col = "";
  $ii++;
}

Edit: Actually, it's not any shorter.. I thought it would be but that's only because I forgot a part.. :X
 
Last edited:
0
•••
Dynadot — .com Registration $8.99Dynadot — .com Registration $8.99
Appraise.net

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Payment Flexibility
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back