runnerjp Posted October 30, 2008 Share Posted October 30, 2008 would i be able to change the table colours by doing somethign such as sticking in in some kind of loop and echoing it out in a class ?? as you can see my data is large so this would be the easyest option i belive? <tr class='mainrow'><td valign='top'><div align="center"><strong> <?php //We need to add a Little variable that will automatically increase so that //Each div (container) in the editforum.php script is unique: $CONT_ID = 1; ?> <a href='/members/<? echo $gettopic3['author']; ?>'><? echo $gettopic3['author'] ?></a></strong><a href='/members/<? echo $gettopic3['author']; ?>'></a> <?php $result = mysql_query("SELECT * FROM useronline WHERE(user='".$gettopic3['author']."')"); while($row = mysql_fetch_array( $result )) { $last_active = time() - $row['timestamp']; } if($last_active < 300) { echo '<img src="http://www.runningprofiles.com/images/useron.gif" width="12" height="11" />'; } else { echo '<img src="http://www.runningprofiles.com/images/useroff.gif" width="12" height="11" />'; } }?></div> <p align="center"> <? $query = "SELECT * FROM users WHERE Username = '".$gettopic3['author']."' LIMIT 1"; if ($result = mysql_query($query)){ if (mysql_num_rows($result)) { $array = mysql_fetch_assoc($result); $image = $array['image']; $postnum = $array['post_count']; echo "<img src=\"http://www.runningprofiles.com/members/images/mini/$image\" border=\"1\" />";?><br /> <span class="style7">Posts: <?php echo $postnum;?></span> <? } ?> </td> <td valign='top'><table width="100%" cellspacing="0" cellpadding="0"> <tr> <td width="3%" rowspan="2"><div align="center"><img src="http://www.runningprofiles.com/images/posted.jpg" width="17" height="33" /></div></td> <td width="97%" colspan="2" valign="top"><a href='index.php?page=message&forum=<? echo $forum; ?>&id=<? echo $gettopic3[postid] ?>'><strong><? echo $gettopic3[title] ?></strong></a></td> </tr> <tr> <td valign="top"><span class="style7">Posted <? $dbtime=$gettopic3['showtime']; $time = date("F j Y, g:i a", $dbtime); ?> <? $dbtime = $gettopic3['lastrepliedto']; $time = date("F j, Y, g:i a", $dbtime); // Get current timestamp $intTime = time(); // Calculate difference $intDiff = $intTime - $dbtime; // Check time switch($intDiff) { case ($intDiff < 60): echo "<strong>Less than a minute ago</strong>"; break; case ($intDiff < 3600): echo "<strong>Less than an hour ago</strong>"; break; case ($intDiff < 7200): echo "<strong>One hour ago</strong>"; break; case ($intDiff < 10800): echo "<strong>Two hours ago</strong>"; break; case ($intDiff < 86400): echo "<strong>Today</strong>"; break; case ($intDiff < 172800): echo "<strong>Yesterday</strong>"; break; default: echo $time; } ?> </span></td> <td align="right" valign="bottom"><form action="index.php?page=reply&id=<? echo $id ?>" method="post" name="quote"> <input name="quote" type="hidden" value="<? echo $gettopic3['postid'];?>" /> <input type="submit" value="quote" /> </form></td> </tr> <tr> <td> </td> <td colspan="2"><hr color="#CCCCCC" /></td> </tr> <tr> <td> </td> <td height="90" colspan="2" align="left" valign="top"><?php echo $gettopic3['post'];?></td> </tr> </table></td> </tr> Link to comment https://forums.phpfreaks.com/topic/130793-alternating-table-colours/ Share on other sites More sharing options...
n3ightjay Posted October 31, 2008 Share Posted October 31, 2008 for loop would be the easiest then you already have a counter going but you could create a counter for a while loop.. sorry you'll have to figure out which of the following work better for you im to lazy to look through your code to figure out where / what your talking about $counter = 0; while(true){ if($counter % 2 == 0){ $class = "class1"; }else{ $class = "class2"; } $counter++; } or for($i = 0;$i <= $whatever;$i++){ if($counter % 2 == 0){ $class = "class1"; }else{ $class = "class2"; } } Link to comment https://forums.phpfreaks.com/topic/130793-alternating-table-colours/#findComment-679027 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.