Warptweet Posted March 21, 2007 Share Posted March 21, 2007 My database organises uploads by their ID number. Each time somebody uploads a file, it's ID number is 1 higher than the previous one. How would I display the row in my database that is the SECOND highest? (Not the highest) and what about the THIRD highest? FOURTH highest? I use this code as my BASE... <?php $con = mysql_connect("localhost","peter","abc123"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("my_db", $con); $result = mysql_query("SELECT * FROM accepted_uploads WHERE uploadid='somenumer'"); while($row = mysql_fetch_array($result)) { echo $row['FirstName'] . " " . $row['LastName']; echo "<br />"; } ?> Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted March 21, 2007 Share Posted March 21, 2007 Display last 5: $query = "SELECT * FROM tablename ORDER BY id DESC LIMIT 5"; $result = mysql_query($query) or die(mysql_error()); echo ' <table> <tr> <th>Order</th> <th>Name</th> </tr>'; while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo ' <tr> <td>' . $i . '</td> <td>' . $row['LastName'] . ', ' . $row['FirstName'] . '</td> </tr>'; } echo ' </table>'; Change the LIMIT clause on the sql query to select different ones...for example "LIMIT 1" would get the most recent, "LIMIT 1, 1" would get the second most recent. 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.