bobicles2 Posted April 22, 2010 Share Posted April 22, 2010 Is this possible? im looking to display the top 10 most recently added items to my table on the homepage any ideas? thanks Quote Link to comment https://forums.phpfreaks.com/topic/199403-sql-query-to-show-recently-added-items/ Share on other sites More sharing options...
MadTechie Posted April 22, 2010 Share Posted April 22, 2010 add a timestamp field and then ORDER BY timestamp DESC LIMIT 10 Quote Link to comment https://forums.phpfreaks.com/topic/199403-sql-query-to-show-recently-added-items/#findComment-1046512 Share on other sites More sharing options...
bobicles2 Posted April 22, 2010 Author Share Posted April 22, 2010 add a timestamp field and then ORDER BY timestamp DESC LIMIT 10 just adding the field now, does it need any particular variables, or will it be added naturally ive set the field type to TIMESTAMP Quote Link to comment https://forums.phpfreaks.com/topic/199403-sql-query-to-show-recently-added-items/#findComment-1046521 Share on other sites More sharing options...
MadTechie Posted April 22, 2010 Share Posted April 22, 2010 if you set the default to current_time/NOW() it should be fine Quote Link to comment https://forums.phpfreaks.com/topic/199403-sql-query-to-show-recently-added-items/#findComment-1046523 Share on other sites More sharing options...
bobicles2 Posted April 22, 2010 Author Share Posted April 22, 2010 if you set the default to current_time/NOW() it should be fine mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM Events ORDER BY timestamp DESC LIMIT 10"; $result=mysql_query($query); $num=mysql_numrows($result); i use this, and it works and echo's everything fine when i used the query SELECT * FROM Events but doesnt work with the new query despite me having a timestamp field in my database having the default as timestamp i checked my databse and when i add an entry the timestamp is added so im not sure whats going wrong Quote Link to comment https://forums.phpfreaks.com/topic/199403-sql-query-to-show-recently-added-items/#findComment-1046532 Share on other sites More sharing options...
MadTechie Posted April 22, 2010 Share Posted April 22, 2010 if SELECT * FROM Events ORDER BY timestamp DESC LIMIT 10 works why are you using SELECT * FROM Events ? Quote Link to comment https://forums.phpfreaks.com/topic/199403-sql-query-to-show-recently-added-items/#findComment-1046542 Share on other sites More sharing options...
bobicles2 Posted April 22, 2010 Author Share Posted April 22, 2010 if SELECT * FROM Events ORDER BY timestamp DESC LIMIT 10 works why are you using SELECT * FROM Events ? sorry i meant it to mean it doesnt work... but when i used Select * From Events it works fine.. so theres a problem with the query ive solved this now though using a different method..i have a field for ID which is set to auto increment so just changed it to display the 10 highest ID's (which are obviously the most recently added events) thanks for the help though much appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/199403-sql-query-to-show-recently-added-items/#findComment-1046559 Share on other sites More sharing options...
MadTechie Posted April 22, 2010 Share Posted April 22, 2010 Query looks fine, while ordering by prime ID will work, you may run into trouble if you need to update the code to order by recently updated! Quote Link to comment https://forums.phpfreaks.com/topic/199403-sql-query-to-show-recently-added-items/#findComment-1046565 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.