Problem with queries!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Emmash
    New Member
    • Oct 2008
    • 10

    Problem with queries!

    Hi,

    I have a query like :

    Code:
    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 :

    Code:
    while($ligne=mysql_fetch_array($requete)){
    ...
    }
    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!!!

    Marie-Hélène
    Last edited by Markus; Oct 22 '08, 03:49 PM. Reason: added # tags
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    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.

    Comment

    • Emmash
      New Member
      • Oct 2008
      • 10

      #3
      I found the solution by reading in MYSQL Documentation.. .. Here is the solution :

      [PHP]SELECT no_document,tit re_document FROM document WHERE no_document=3 OR no_document=1 OR no_document=2 ORDER BY FIELD(no_docume nt,'3','1','2')[/PHP]

      Comment

      Working...