Jump to content

if reached last row in query


jamkelvl

Recommended Posts

Probably not the most efficient but it works

 

$Result = MySQL_Query("SELECT * FROM contacts WHERE active = '1'");
$num_rows = mysql_num_rows($Result);
print $num_rows.' Records<br><br>';
$i=1;
	while ($Row = MySQL_Fetch_Array($Result))
	{
		if ($i == $num_rows)
		{
			print 'This is the last row! '.$Row[p_id].'<br>';
		}
		else
		{
			print 'This is not the last row. '.$Row[p_id].'<br>';
		}
		$i++;
	}

 

Output:

 

2 Records

This is not the last row. 1
This is the last row! 2

 

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.