Jump to content

[SOLVED] alternating table background color


Lambneck

Recommended Posts

Hopefully this will work.

 

 

<?php
   
$result = mysql_query("SELECT submission_id, col_1, name, submission_date FROM $table WHERE topic_id = '0' ORDER BY submission_id DESC");

if (!$result) {
    die("Query to show fields from table failed:".mysql_error());
}

$i = 0;

while($row = mysql_fetch_array($result))
{
   $sql = "SELECT * FROM $table WHERE topic_id = " . $row['submission_id'];
   $comments = mysql_query($sql) or die("Error ". mysql_error(). " with query ". $sql);
   
   $count = mysql_num_rows($comments);
         
   $num = mysql_num_rows($result); 
   
   
   if(($i%2) == 0 ) $class = 'EVEN' : $class = 'ODD';
    
      echo '<tr class='".$class."' >';    
      echo '<td class="forumtd"><strong>';
      echo '<a href="topic.php?id='.$row['submission_id'].'">'.stripslashes(htmlspecialchars($row['col_1'])).'</a>';
      echo "</strong></td>";
      echo '<td class="forumtd"><em>';
      echo stripslashes(htmlspecialchars($row['name']));
      echo "</em></td>";
      echo '<td class="forumtd">';
      echo $count;
      echo "</td>";
      echo '<td class="forumtd">';
      echo date("l M dS, Y", $row['submission_date']);
      echo "</td>";
      echo "</tr>";

$i++;
   
   

}
mysql_free_result($result);
?>

Ok well use this code:

 

I wanted you to use the cleaner code but just use this so you can be on your way...

 

 

<?php
   
$result = mysql_query("SELECT submission_id, col_1, name, submission_date FROM $table WHERE topic_id = '0' ORDER BY submission_id DESC");

if (!$result) {
    die("Query to show fields from table failed:".mysql_error());
}

$i = 0;

while($row = mysql_fetch_array($result))
{
   $sql = "SELECT * FROM $table WHERE topic_id = " . $row['submission_id'];
   $comments = mysql_query($sql) or die("Error ". mysql_error(). " with query ". $sql);
   
   $count = mysql_num_rows($comments);
         
   $num = mysql_num_rows($result); 
   
   
   if(($i%2) == 0 ) {
   $class = 'EVEN';
   }else{
   $class = 'ODD';
   }
    
      echo '<tr class='".$class."' >';    
      echo '<td class="forumtd"><strong>';
      echo '<a href="topic.php?id='.$row['submission_id'].'">'.stripslashes(htmlspecialchars($row['col_1'])).'</a>';
      echo "</strong></td>";
      echo '<td class="forumtd"><em>';
      echo stripslashes(htmlspecialchars($row['name']));
      echo "</em></td>";
      echo '<td class="forumtd">';
      echo $count;
      echo "</td>";
      echo '<td class="forumtd">';
      echo date("l M dS, Y", $row['submission_date']);
      echo "</td>";
      echo "</tr>";

$i++;
   
   

}
mysql_free_result($result);
?>

Woohoo!! It works! thanks man, you really live up to your name!  ;)

 

No problem, I would have rather had you use the cleaner code but it's really no biggie...

 

I just wanted to get you on your way so you're not stuck on this all day....

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.