Jump to content

looping


astralaaron

Recommended Posts

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

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

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

Archived

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

×
×
  • Create New...