mike12255 Posted February 16, 2009 Share Posted February 16, 2009 I got the following css: #box1{ color:#999999; font: normal 12px; background-color:#999999; } #box2{ color:#000000; font: normal 12px; background-color:#FFFFFF; } And the code for this page : http://www.schoolworkanswers.com/math.php is here: <?php print "<link rel='stylesheet' href='style.css' type='text/css'>"; print ("<A href='post.php'>New Topic</a> -"); print ("<A href='register.php'>Register</a> -"); //print("<A href='main.php'>Control Panel</a> ");// correct way print "<table class='maintable'>"; print "<tr class='headline'><td width=50%>Topic</td><td width=20%>Topic Starter</td><td>Replies</td><td> Last replied by</td></tr>"; $getthreads="SELECT * from forumtutorial_posts where parentid='0' order by lastrepliedto DESC"; $getthreads2=mysql_query($getthreads) or die("Could not get threads"); while($getthreads3=mysql_fetch_array($getthreads2)) { $getthreads3[title]=strip_tags($getthreads3[title]); $getthreads3[author]=strip_tags($getthreads3[author]); print "<tr class='mainrow'><td><A href='message.php?id=$getthreads3[postid]'>$getthreads3[title]</a></td><td>$getthreads3[author]</td><td>$getthreads3[numreplies]</td><td> <b>$getthreads3[lastposter]</b></td></tr>"; } print "</table>"; ?> I want it so it alternates that the first post has a grey background and the second a white and the third a grey and the fourth a white ect ect im not sure how to do it with those two codes though. Quote Link to comment Share on other sites More sharing options...
popcornplya Posted February 17, 2009 Share Posted February 17, 2009 $box = '#box1'; if($box == '#box1') { $box = '#box2'; } then just do id="$box" Quote Link to comment Share on other sites More sharing options...
haku Posted February 17, 2009 Share Posted February 17, 2009 The last poster had the right idea, except that you can't use IDs more than once, so you would want to set it as a class name. Change this: while($getthreads3=mysql_fetch_array($getthreads2)) { $getthreads3[title]=strip_tags($getthreads3[title]); $getthreads3[author]=strip_tags($getthreads3[author]); print "<tr class='mainrow'><td><A href='message.php?id=$getthreads3[postid]'>$getthreads3[title]</a></td><td>$getthreads3[author]</td><td>$getthreads3[numreplies]</td><td> <b>$getthreads3[lastposter]</b></td></tr>"; } to this: $color = 'grey'; while($getthreads3=mysql_fetch_array($getthreads2)) { $getthreads3[title]=strip_tags($getthreads3[title]); $getthreads3[author]=strip_tags($getthreads3[author]); print "<tr class='mainrow"; print " " . $color; print "'><td><A href='message.php?id=$getthreads3[postid]'>$getthreads3[title]</a></td><td>$getthreads3[author]</td><td>$getthreads3[numreplies]</td><td> <b>$getthreads3[lastposter]</b></td></tr>"; $color = ($color == 'grey') ? 'white' : 'grey'; } Then add this to your CSS: .grey { color:#999; } .white { color:#FFF; } Quote Link to comment Share on other sites More sharing options...
mike12255 Posted February 17, 2009 Author Share Posted February 17, 2009 OK, thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.