Jump to content

Checking if lowest value


EchoFool

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/91743-checking-if-lowest-value/
Share on other sites

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

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"

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.