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? Quote Link to comment 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 Quote Link to comment 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.