By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,890 Members | 1,039 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,890 IT Pros & Developers. It's quick & easy.

Problem with queries!

P: 10

I have a query like :

Expand|Select|Wrap|Line Numbers
  1. SELECT no_document,titre_document FROM document WHERE no_document=3 OR no_document=1 OR no_document=2
and I have a loop like :

Expand|Select|Wrap|Line Numbers
  1. while($ligne=mysql_fetch_array($requete)){
  2. ...
  3. }
When I display the results in the loop, I get document 1, document 2 and document 3 displayed instead of document 3, document 1 and document 2 like in my where clause.

Is there a way to keep the order like the order in the WHERE clause because my results always seems to re-order automatically by id...

Thanks to help me!!!

Oct 22 '08 #1
Share this Question
Share on Google+
2 Replies

Expert 5K+
P: 6,050
Please use [code] tags when posting code in the forums.

Your WHERE clause is pointless because it's not saying 'display 3 first, then 1 and then 2' it's saying 'display anything where no_document = 1, 2 or 3'.

And I've never come across the need to do this, so I look forward to seeing a solution.
Oct 22 '08 #2

P: 10
I found the solution by reading in MYSQL Documentation.... Here is the solution :

[PHP]SELECT no_document,titre_document FROM document WHERE no_document=3 OR no_document=1 OR no_document=2 ORDER BY FIELD(no_document,'3','1','2')[/PHP]
Oct 22 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.