senyo Posted June 11, 2010 Share Posted June 11, 2010 Hi I am trying to get the last record of a query in a variable from a list of 100 records this is the code I use to get the last 100 records from a db $query = "SELECT * FROM entry WHERE entry.ok='1' ORDER BY id DESC LIMIT 100"; $result = mysql_query($query); // Display records from the table echo "<table border='1'>"; while ($row = mysql_fetch_array($result, MYSQL_NUM)) { echo "<tr><td>$row[0]</td><td>$row[1]</td><td>$row[2]</td></tr>"; } What should I use so that the record with the number 100 is placed in a variable? Link to comment https://forums.phpfreaks.com/topic/204476-working-with-the-last-record-of-a-query/ Share on other sites More sharing options...
pdkv2 Posted June 11, 2010 Share Posted June 11, 2010 $query = "SELECT * FROM entry WHERE entry.ok='1' ORDER BY id DESC LIMIT 100"; $result = mysql_query($query); // Display records from the table $hundredth_record=array(); $rec_num=1; echo "<table border='1'>"; while ($row = mysql_fetch_array($result, MYSQL_NUM)) { echo "<tr><td>$row[0]</td><td>$row[1]</td><td>$row[2]</td></tr>"; if($rec_num==100){ $hundredth_record=$row; } $rec_num++; } $hundredth_record will contain the record with the number 100 Link to comment https://forums.phpfreaks.com/topic/204476-working-with-the-last-record-of-a-query/#findComment-1070748 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.