astralaaron Posted December 28, 2007 Share Posted December 28, 2007 how do you loop information in a table and have the rows change between 2 colors?? Link to comment Share on other sites More sharing options...
Ingolme Posted December 28, 2007 Share Posted December 28, 2007 You can do it by checking the modulus of 2 of the result number.$n = 0;while ($row = mysql_fetch_array([Previously made query])) {if($n%2 == 0) {$css = "classname1";} else {$css = "classname2";}echo "<tr>\n";echo "<td class= \"" . $css . "\">[some information]</td>\n";echo "<tr>\n";$n++} Link to comment Share on other sites More sharing options...
astralaaron Posted December 28, 2007 Author Share Posted December 28, 2007 You can do it by checking the modulus of 2 of the result number.$n = 0;while ($row = mysql_fetch_array([Previously made query])) {if($n%2 == 0) {$css = "classname1";} else {$css = "classname2";}echo "<tr>\n";echo "<td class= \"" . $css . "\">[some information]</td>\n";echo "<tr>\n";$n++}thanks Link to comment Share on other sites More sharing options...
astralaaron Posted December 28, 2007 Author Share Posted December 28, 2007 i tried a few times I cannot get it working...i set $n = 0;at the top of the page <table class="viewer"> <tr> <td width="10px"><span class="title_span">ID:</span></td> <td><span class="title_span">Gallery name:</span></td> <td width="*"><span class="title_span">Catagory</span></td> <td width="20px"><span class="title_span">added:</span></td> </tr> <?php while($row=mysql_fetch_array($result1)){ if($n%2 == 0) { $css = "viewer"; } else { $css = "viewer2"; } ?> <tr> <td class="<?php echo $css; ?>"><span class="date_b"><?php echo $row['id']; ?></span></td> <td class="<?php echo $css; ?>"><a href="viewer.php?gallery_id=<?php echo $row['uni_id']; ?>&title=<?php echo $row['name']; ?>"><?php echo $row['name']; ?></td> <td class="<?php echo $css; ?>"><span class="date_b"><?php echo $row['category']; ?></span></td> <td class="<?php echo $css; ?>"><span class="date_b"><?php echo $row['date1']; ?></span></td> </tr> <?php $n++; } ?> </table> Link to comment Share on other sites More sharing options...
Ingolme Posted December 28, 2007 Share Posted December 28, 2007 Hmm...It seems right to me, are you sure that <span class="date_b"> and <table class="viewer"> aren't interfering with the table cell style? Link to comment Share on other sites More sharing options...
shiftJIS Posted December 29, 2007 Share Posted December 29, 2007 I also can't see the issue from the code provided. It does seem strange that you're using the .viewer class for both the table and the individual .tdWe'll need to see a sample of your .css file in order to be more help... Link to comment Share on other sites More sharing options...
murfitUK Posted December 29, 2007 Share Posted December 29, 2007 Ignore - I'm talking rubbish. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.