whare Posted August 7, 2006 Share Posted August 7, 2006 Hi All Me again :)right im trying to work out how to show only the newest entries into the sql db basicly like a preview of what has happend latly but i have no idea how to do (I no I need to get a php book lol well I got one on order lol)so can anybody tell me how or point me towards something that tells me how ThanxWhare[sorry no code to show you what i got not started working on it yet] Link to comment https://forums.phpfreaks.com/topic/16825-only-show-x-results/ Share on other sites More sharing options...
alecjw Posted August 7, 2006 Share Posted August 7, 2006 Instead of:[code]while($row=mysql_fetch_row($result)){//Some code}[/code]Use:[code]$shown=0;$toshow=12;while($row=mysql_fetch_row($result)){if($show<=$toshow){//Some code}}[/code]To show the most RECENT mysql rows, put desc after the ORDER BY id bit. (ORDER BY id desc)EDIT: You can change $toshow=12 to $toshow=the number of rows you want to show. Link to comment https://forums.phpfreaks.com/topic/16825-only-show-x-results/#findComment-70813 Share on other sites More sharing options...
whare Posted August 7, 2006 Author Share Posted August 7, 2006 Thanx mate that should help me out alot :) Link to comment https://forums.phpfreaks.com/topic/16825-only-show-x-results/#findComment-70815 Share on other sites More sharing options...
Barand Posted August 7, 2006 Share Posted August 7, 2006 If you just want, say, the 10 latest,[code]SELECT blah1, blah2 FROM mytablename ORDER BY id DESC LIMIT 10[/code] Link to comment https://forums.phpfreaks.com/topic/16825-only-show-x-results/#findComment-70816 Share on other sites More sharing options...
Barand Posted August 7, 2006 Share Posted August 7, 2006 @alecjw,You need to increment $show (or $shown depending on which variable name you finally settle on) Link to comment https://forums.phpfreaks.com/topic/16825-only-show-x-results/#findComment-70817 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.