jamkelvl Posted February 2, 2010 Share Posted February 2, 2010 Trying to do something if last row in query has been reached. All other code omitted. <?php // get results while($row = mysql_fetch_array($result)){ extract($row); // if last row display echo '('.$initials.' * 1);'; // else echo '('.$initials.' * 1) + '; } ?> Any help? Link to comment https://forums.phpfreaks.com/topic/190613-if-reached-last-row-in-query/ Share on other sites More sharing options...
Haberdasher Posted February 2, 2010 Share Posted February 2, 2010 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 Link to comment https://forums.phpfreaks.com/topic/190613-if-reached-last-row-in-query/#findComment-1005354 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.