shamwowy Posted August 7, 2011 Share Posted August 7, 2011 Hi all, dumb question I'm sure but not finding the answer so far... I'm trying to reference the row number in a sql query resultset loop. if( $r = mysql_query($query1) ) // LOTS AND LOTS OF ROWS RETURNED { while( $row = mysql_fetch_assoc($r) ) // LOOP { print "Phone - {$row['jloc_phone']}<br/>"; print "This is record number ".$what_var_here."<br/>"; //HOW TO REFENCE MY ROW NUMBER HERE? } } } I've tried variations with $row and $r which return either "Array" or "resource". I'm assuming it's something like $row[count] or some such thing that I'm just not finding. Many thanks in advance for any assistance on this. Quote Link to comment https://forums.phpfreaks.com/topic/244110-referencing-a-row-number-in-result-set/ Share on other sites More sharing options...
trq Posted August 7, 2011 Share Posted August 7, 2011 if( $r = mysql_query($query1) ) // LOTS AND LOTS OF ROWS RETURNED { $counter = 1; while( $row = mysql_fetch_assoc($r) ) // LOOP { print "Phone - {$row['jloc_phone']}<br/>"; print "This is record number ".$counter."<br/>"; //HOW TO REFENCE MY ROW NUMBER HERE? $counter++; } } Quote Link to comment https://forums.phpfreaks.com/topic/244110-referencing-a-row-number-in-result-set/#findComment-1253642 Share on other sites More sharing options...
shamwowy Posted August 7, 2011 Author Share Posted August 7, 2011 Many thanks! I had thought there would be something I could reference directly in the result object itself but this works too. Quote Link to comment https://forums.phpfreaks.com/topic/244110-referencing-a-row-number-in-result-set/#findComment-1253677 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.