monkeytooth Posted October 28, 2008 Share Posted October 28, 2008 Alright, never wanted to do this before, but now have a need, and I am sure this is a simple well hopefully simple answer. The query I go, listing it thought PHP no problem. But I want it reversed. I am taking the last 10 entries and displaying them. But it displays 10-1 where as I want 1-10 Currently using your basic while loop to run the fetched array but how I should get it sorted is lost on me at the moment.. do I do something in the while loop to make it go 1 to 10 or do I do something the the query itself? Quote Link to comment https://forums.phpfreaks.com/topic/130479-solved-phpmysql-sorting-confused-help/ Share on other sites More sharing options...
sasa Posted October 28, 2008 Share Posted October 28, 2008 usr SELECT * FROM (SELECT * FROM table ORDER BY field DESC LIMIT 10) ORDER BY field ASC Quote Link to comment https://forums.phpfreaks.com/topic/130479-solved-phpmysql-sorting-confused-help/#findComment-676877 Share on other sites More sharing options...
monkeytooth Posted October 28, 2008 Author Share Posted October 28, 2008 Kick arse, thank ya.. I thought it was something like that but I was using the wrong concept to it.. Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/130479-solved-phpmysql-sorting-confused-help/#findComment-676917 Share on other sites More sharing options...
monkeytooth Posted October 28, 2008 Author Share Posted October 28, 2008 Ok that works but what I failed to mention but now realize is the parameters... Orginal concept: $mycrecs2z = " SELECT * FROM comp_jobs WHERE jstatus = 'active' "; $mycrecs2az = mysql_query($mycrecs2z) or die('1 Error, query failed<br>' . mysql_error()); What I have is a database with listings that are active and inactive. So i guess what I wrote orginally is kind of off.. What I need is the first 10 entries in the database that are "active" where in this database it could be 100 entries only 10 active but at diffrent places through out the 100 and can be changed at any time. to only 8 or 50 or all 100, but over all I want to list only active in this particular portion of the site, and the most recent of them sorting them so that the last entry to the database (thee most recent is first in the array) Quote Link to comment https://forums.phpfreaks.com/topic/130479-solved-phpmysql-sorting-confused-help/#findComment-676927 Share on other sites More sharing options...
monkeytooth Posted October 28, 2008 Author Share Posted October 28, 2008 Nevermind, answered my own question with a bit of playin around, man i feel out of it.. ever work to much on something and just.. ehhhhh.. yea.. anyway what worked for me was... $mycrecs2z = " SELECT * FROM comp_jobs WHERE jstatus = 'active' ORDER BY ID DESC LIMIT 10"; $mycrecs2az = mysql_query($mycrecs2z) or die('1 Error, query failed<br>' . mysql_error()); mysql_close(); Quote Link to comment https://forums.phpfreaks.com/topic/130479-solved-phpmysql-sorting-confused-help/#findComment-676950 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.