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);
?>

Link to comment
Share on other sites

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);
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.