Jump to content

[SOLVED] what row am i on?


nezbo

Recommended Posts

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

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>

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

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.