webguync Posted March 19, 2008 Share Posted March 19, 2008 I have mastered the art of displaying results from MySQL into a web page via SQL Queries and while ($row = mysql_fetch_array($result)) { what I need to do though and am not sure how to go about it is to display only the last record entered into MySQL into my html table, so that each and every time a new record is entered that (1) and only one is displayed. thanks in advance for any assistance. Quote Link to comment https://forums.phpfreaks.com/topic/96812-show-last-record-entered-as-default/ Share on other sites More sharing options...
alecks Posted March 19, 2008 Share Posted March 19, 2008 If you have a 'time' column filled with timestamps of when the row is added, you can make a query like SELECT * FROM table ORDER BY time DESC LIMIT 1 Quote Link to comment https://forums.phpfreaks.com/topic/96812-show-last-record-entered-as-default/#findComment-495440 Share on other sites More sharing options...
JSHINER Posted March 19, 2008 Share Posted March 19, 2008 Assign an ID to each then "SELECT * FROM table ORDER BY id DESC LIMIT 1" Quote Link to comment https://forums.phpfreaks.com/topic/96812-show-last-record-entered-as-default/#findComment-495441 Share on other sites More sharing options...
teng84 Posted March 19, 2008 Share Posted March 19, 2008 you may use <a href="http://www.php.net/manual/en/function.mysql-insert-id.php">mysql_insert_id</a> if you're using the current connection.. Quote Link to comment https://forums.phpfreaks.com/topic/96812-show-last-record-entered-as-default/#findComment-495449 Share on other sites More sharing options...
webguync Posted March 19, 2008 Author Share Posted March 19, 2008 thanks for the ideas. I got a working script using a timestamp and sorting desc limit 1 Quote Link to comment https://forums.phpfreaks.com/topic/96812-show-last-record-entered-as-default/#findComment-495464 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.