Jump to content

[SOLVED] Problems with queries


Emmash

Recommended Posts

Hi,

 

I have a query like :

 

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 :

 

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

Link to comment
Share on other sites

There isn't a way (that I'm aware of) to order by the order of your WHERE clause.

 

On a side note, your query could be made simpler.

 

SELECT no_document,titre_document FROM document WHERE no_document IN(3,1,2);

 

Same problem... the documents are not ordered as the value in the "IN" clause...

 

I get again document 1, 2, 3 instead of 3,1,2

Link to comment
Share on other sites

Same problem... the documents are not ordered as the value in the "IN" clause...

 

Thore told you you can't do it:

 

There isn't a way (that I'm aware of) to order by the order of your WHERE clause.

 

On a side note, your query could be made simpler.

 

SELECT no_document,titre_document FROM document WHERE no_document IN(3,1,2);

 

Looks like you may need to re think it or do three sperate querys.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.