H-Fish Posted February 16, 2003 Share Posted February 16, 2003 i have a table called tabs, and from this table i want to retrive data from columns: artist & title BUT i only want to get the 5 most recent submitted entries is this possible? Quote Link to comment https://forums.phpfreaks.com/topic/160-retrieve-top-5-most-recent-added-entries-in-sql-table/ Share on other sites More sharing options...
effigy Posted February 16, 2003 Share Posted February 16, 2003 do you have a timestamp or id field so the db can determine who is the most recent? if so: select artist, title from table order by id_or_time_field desc limit 5 what kind of art site? i\'m interested Quote Link to comment https://forums.phpfreaks.com/topic/160-retrieve-top-5-most-recent-added-entries-in-sql-table/#findComment-471 Share on other sites More sharing options...
H-Fish Posted February 17, 2003 Author Share Posted February 17, 2003 i\'ve got an id field, but do i like put id field 1 in there..... heres a what my table looks like from phpmyadmin btw you can see it at www.clansr.co.uk/cs/hctabs it just a little selection of scripts where me and my friends can share guitar tabs Quote Link to comment https://forums.phpfreaks.com/topic/160-retrieve-top-5-most-recent-added-entries-in-sql-table/#findComment-476 Share on other sites More sharing options...
pallevillesen Posted February 17, 2003 Share Posted February 17, 2003 If your ID field is auito_increment then select artist, title from table order by id desc limit 5; will give you the 5 records with the highest ID numbers P. Quote Link to comment https://forums.phpfreaks.com/topic/160-retrieve-top-5-most-recent-added-entries-in-sql-table/#findComment-477 Share on other sites More sharing options...
H-Fish Posted February 17, 2003 Author Share Posted February 17, 2003 thanks but i just need one more little thing...., will i have to decaler this as a variable / string or just echo mysql_result i\'m at school ahnd havent got the chnace to look at my code so i might just be talking crap to myself Quote Link to comment https://forums.phpfreaks.com/topic/160-retrieve-top-5-most-recent-added-entries-in-sql-table/#findComment-478 Share on other sites More sharing options...
H-Fish Posted February 17, 2003 Author Share Posted February 17, 2003 cheers i did it with this code ///////// READS INFO FROM DATABASE /////// mysql_connect("localhost","clanrryoy",""); @mysql_select_db($DB_DBName) or die( "Unable to select database"); $query="SELECT artist, title FROM tabs order by id desc limit 5"; $result=mysql_query($query); $num=mysql_numrows($result); $i=0; while ($i < $num) { $artist=mysql_result($result,$i,"artist"); $title=mysql_result($result,$i,"title"); ?> <? // ADDS READ DATA INTO PAGE ?> <p> </p> <div align="center"> <p><? echo "$artist"; ?><br> <? echo "$title"; ?> <? ++$i; } echo "</table>"; Quote Link to comment https://forums.phpfreaks.com/topic/160-retrieve-top-5-most-recent-added-entries-in-sql-table/#findComment-481 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.