Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^2: Sort AoH by another array

by saberworks (Curate)
on Nov 06, 2007 at 01:38 UTC ( [id://649132]=note: print w/replies, xml ) Need Help??


in reply to Re: Sort AoH by another array
in thread Sort AoH by another array

Thanks, I agree about the data structure. It's generated from an SQL query with an IN () clause. The results have to be ordered in the order the user selected the items (using a web interface). I don't think there's a way to do that directly with an SQL ORDER BY clause. I will use the suggestions here for a lookup hash, thanks again.

Replies are listed 'Best First'.
Re^3: Sort AoH by another array
by Cody Pendant (Prior) on Nov 06, 2007 at 05:15 UTC
    The results have to be ordered in the order the user selected the items (using a web interface). I don't think there's a way to do that directly with an SQL ORDER BY clause.

    I thought that too, and then I discovered this:

    SELECT * FROM table ORDER BY FIELD( foo, 4, 2, 5, 1, 3 );

    I'm not sure which versions of MySQL it works in, but definitely in 5.

    Note there's a bug where you can't have a space between FIELD and the bracket.



    Nobody says perl looks like line-noise any more
    kids today don't know what line-noise IS ...
      Hi, Thanks for your suggestion. Our application supports Oracle 9 & 10, and Postgres 8 (not MySQL). I will try that and see if it works, it will be a lot easier in this case.

      Update: it appears PostgreSQL doesn't support this.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://649132]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2024-03-29 11:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found