469,088 Members | 1,273 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,088 developers. It's quick & easy.

force order

I'm working on a web page in php with a mysql DB. I'm trying to list
some products with some other information but I'm having trouble tying
them together. Is there a way to force a very specific order to be
returned? What I need to be able to do is have a query like

"select * from products where prodID = 'thing1' or prodID = 'thing2'
or prodID = 'thing3'...

but I need it to come back in that EXACT order, product matching
thing1 first thing2 second and so on.

Any ideas?

Thanks,
Tim
Jul 19 '05 #1
3 2382
Odarr wrote:
I'm working on a web page in php with a mysql DB. I'm trying to list
some products with some other information but I'm having trouble tying
them together. Is there a way to force a very specific order to be
returned? What I need to be able to do is have a query like

"select * from products where prodID = 'thing1' or prodID = 'thing2'
or prodID = 'thing3'...

but I need it to come back in that EXACT order, product matching
thing1 first thing2 second and so on.


use:
order by fieldname
at the end of your query.

Instead of names, use integer id values in the field which you want to
use for ordering, that way you can easily deside that 'thing1' = 1,
'thing2' = 2, etc, and ordering them is simple and fast.

Jul 19 '05 #2
Odarr wrote:
I'm working on a web page in php with a mysql DB. I'm trying to list
some products with some other information but I'm having trouble tying
them together. Is there a way to force a very specific order to be
returned? What I need to be able to do is have a query like

"select * from products where prodID = 'thing1' or prodID = 'thing2'
or prodID = 'thing3'...

but I need it to come back in that EXACT order, product matching
thing1 first thing2 second and so on.


use:
order by fieldname
at the end of your query.

Instead of names, use integer id values in the field which you want to
use for ordering, that way you can easily deside that 'thing1' = 1,
'thing2' = 2, etc, and ordering them is simple and fast.

Jul 19 '05 #3
Odarr wrote:
I'm working on a web page in php with a mysql DB. I'm trying to list
some products with some other information but I'm having trouble tying
them together. Is there a way to force a very specific order to be
returned? What I need to be able to do is have a query like

"select * from products where prodID = 'thing1' or prodID = 'thing2'
or prodID = 'thing3'...

but I need it to come back in that EXACT order, product matching
thing1 first thing2 second and so on.


use:
order by fieldname
at the end of your query.

Instead of names, use integer id values in the field which you want to
use for ordering, that way you can easily deside that 'thing1' = 1,
'thing2' = 2, etc, and ordering them is simple and fast.

Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Jeronimo Bertran | last post: by
reply views Thread by comp.lang.php | last post: by
2 posts views Thread by Oliver Block | last post: by
2 posts views Thread by Veeru71 | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by kglaser89 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.