wmguk Posted January 12, 2010 Share Posted January 12, 2010 Hi guys, I have a script which displays results in rows in a table, however I need to make the rows alternate 2 colours... <? if($no_menu!=0){ ?> <tr> <td width="75" align="center" class="main">Delete</td> <td align="left" class="main">Property Title</td> <td width="100" align="center" class="main">Property of<br />the Week</td> <td width="80" align="center" class="main">Available</td> <td width="70" align="center" class="main">Display</td> </tr> <? while($row_menu=mysql_fetch_array($result_menu)){ ?> <tr> <td align="center"><a href="editproperty.php?mode=del&pid=<?=base64_encode("$row_menu[pid]")?>" class="link" onClick="return confirm('Are you sure want to delete this data!');" title="Click to Delete">Delete</a></td> <td align="left" class="main"><a href="addproperty.php?pid=<?=base64_encode("$row_menu[pid]")?>" class="link" title="Click to Edit"><strong> <? if ($row_menu['type'] == "C") { echo "Commercial"; } else { echo "Residential"; }?> | <? if ($row_menu['style'] == "A") { echo "Auction"; } elseif ($row_menu['style'] == "L") { echo "Lettings"; } else { echo "Sale"; }?> | <?= stripslashes($row_menu['owner_name'])?> </strong></a></td> <td align="center" class="normaltext1"> <? if($row_menu['feature']=='y'){?> <a href="editproperty.php?mode=feature&pid=<?=base64_encode($row_menu['pid'])?>&flag=n" class="link" onClick="return confirm('Are you sure want to change status?');" title="Click to change Status">Yes</a> <? } else {?> <a href="editproperty.php?mode=feature&pid=<?=base64_encode($row_menu['pid'])?>&flag=y" class="link" onClick="return confirm('Are you sure want to change status?');" title="Click to change Status">No</a> <? }?> </td> <td align="center" class="normaltext1"> <? if($row_menu['let']=='y'){?> <a href="editproperty.php?mode=let&pid=<?=base64_encode($row_menu['pid'])?>&flag=n" class="link" onClick="return confirm('Are you sure want to change status?');" title="Click to change Status">Yes</a> <? } else {?> <a href="editproperty.php?mode=let&pid=<?=base64_encode($row_menu['pid'])?>&flag=y" class="link" onClick="return confirm('Are you sure want to change status?');" title="Click to change Status">No</a> <? }?> </td> <td align="center" class="normaltext1"> <? if($row_menu['flag']=='y'){?> <a href="editproperty.php?mode=display&pid=<?=base64_encode($row_menu['pid'])?>&flag=n" class="link" onClick="return confirm('Are you sure want to change status?');" title="Click to change Status">Yes</a> <? } else {?> <a href="editproperty.php?mode=display&pid=<?=base64_encode($row_menu['pid'])?>&flag=y" class="link" onClick="return confirm('Are you sure want to change status?');" title="Click to change Status">No</a> <? } ?> </td> </tr> <? } } else { ?> <tr> <td colspan="4" align="center" class="main"><strong>No Properties are available.</strong></td> </tr> <? } ?> I've tried to do this, but i cannot get it to alternate... Any ideas? Link to comment https://forums.phpfreaks.com/topic/188201-alternating-row-colors/ Share on other sites More sharing options...
mort Posted January 12, 2010 Share Posted January 12, 2010 Above your while loop you need to do say $count_rows = 0; then first line after your while you need $count_rows++; then where it displays your row color you need if ($count_rows % 2 == 0) { echo "<tr bgcolor="#ffffff">"; } else { echo "<tr bgcolor="#000000">"; } Link to comment https://forums.phpfreaks.com/topic/188201-alternating-row-colors/#findComment-993617 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.