EchoFool Posted February 18, 2008 Share Posted February 18, 2008 If i do query to get all rows for a specific WHERE clause and order it by ID. What i do then is while loop the rows. How ever on the "first" loop i.e the first row being echo'd i want it to say "This is the first row" and the rest do not have it. What i thought was to "Find lowest ID" of the selected rows" ... as it is ordered by ID ... that would surely suggest the lowest ID is the first of the rows right? Can it be done solely with the main query and php or will i need an additional query in the while loop to check if the post is the first or something? Quote Link to comment Share on other sites More sharing options...
soycharliente Posted February 18, 2008 Share Posted February 18, 2008 SELECT * FROM table WHERE field='$value' ORDER BY id ASC // low to high SELECT * FROM table WHERE field='$value' ORDER BY id DESC // high to low If you want just 1 row returned: SELECT * FROM table WHERE field='$value' ORDER BY id ASC LIMIT 1 Quote Link to comment Share on other sites More sharing options...
EchoFool Posted February 18, 2008 Author Share Posted February 18, 2008 Yeh i already have the query made and already have it looped but i need a way to find out that the first row that is looped is the first if you get me so that it will show: id | name | is first 23 | bleh | this is first post 42 | fefw | 56 | fsffs | like that is what I want it to work out. That the first row that comes out of the loop is the first and so will echo the statement "this is the first post" Quote Link to comment Share on other sites More sharing options...
soycharliente Posted February 18, 2008 Share Posted February 18, 2008 I already addressed that in the query. It's sorted by id. I don't understand what's not working. The first row that is returned in the resource is the first post. Quote Link to comment Share on other sites More sharing options...
mikefrederick Posted February 18, 2008 Share Posted February 18, 2008 do this $x=0; while (your while function) { if($x==0) echo "whatever"; $x++; } Quote Link to comment 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.