nezbo Posted July 16, 2008 Share Posted July 16, 2008 How do i get php to tell me what mysql row i am on i am useing a while statement i am trying to change the colour for each <TR> here is my code... while ($row = @mysql_fetch_array($result)) { if(($numofrows - the row i am on) % 2) { echo '<TR bgcolor="#cccccc" valign="top">'; } else { echo '<TR bgcolor="#999999" valign="top">'; } echo "<td align=left><a href=" . $_SERVER['PHP_SELF'] . "?user_identifier=" . $row['CallID'] . " > " . $row['userNumber'] . "</a>" . "</td><td align=left>" . $row['UserName'] . "</td><td align=left>" . $row['FullName'] . "</td><td align=left>" . $row['EmailAddress'] . "</td><td align Link to comment https://forums.phpfreaks.com/topic/115048-solved-what-row-am-i-on/ Share on other sites More sharing options...
nezbo Posted July 16, 2008 Author Share Posted July 16, 2008 Sorry sorted it $numofrows = @mysql_num_rows($result); $counting = 0; while ($row = @mysql_fetch_array($result)) { if(($numofrows - $counting) % 2) { echo '<TR bgcolor="#cccccc" valign="top">'; } else { echo '<TR bgcolor="#999999" valign="top">'; } $counting = $counting+1; echo "<td align=left> Link to comment https://forums.phpfreaks.com/topic/115048-solved-what-row-am-i-on/#findComment-591632 Share on other sites More sharing options...
rhodesa Posted July 16, 2008 Share Posted July 16, 2008 you can also wrap it up in a for loop: for($n=0;$row = @mysql_fetch_array($result);$n++) { $color = ($n % 2) ? '#cccccc' : '#999999'; echo '<TR bgcolor="'.$color.'" valign="top">'; echo "<td align=left><a href=" . $_SERVER['PHP_SELF'] . "?user_identifier=" . $row['CallID'] . " > " . $row['userNumber'] . "</a>" . "</td><td align=left>" . $row['UserName'] . "</td><td align=left>" . $row['FullName'] . "</td><td align=left>" . $row['EmailAddress'] . "</td><td align Link to comment https://forums.phpfreaks.com/topic/115048-solved-what-row-am-i-on/#findComment-591639 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.