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
https://forums.phpfreaks.com/topic/129582-solved-problems-with-queries/
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

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.

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.