Jump to content

SELECT ... ORDER BY an array....


briant

Recommended Posts

I'm new when it comes to arrays. It's pretty confusing but I will try my best to describe what I am trying to accomplish.

 

I would like to SELECT fields from a database and order it. Here is an example.

 

SELECT * FROM mytable ORDER BY ranks;

 

The ranks field has: 11,5,33,2,66,39

So if you were to explode it into an array, the [0] value would be 11.

I want my results to be ordered by the [0] array. How am I to do that?

 

I suppose if you were to nest it, it could work but I'm pretty sure there's an easier way.

 

Thanks for reading... would appreciate any help.

Link to comment
https://forums.phpfreaks.com/topic/90320-select-order-by-an-array/
Share on other sites

If I'm able to explode it and call that [ 0 ] value all in one line, I think, then I'll be able to order it.

 

SELECT * FROM mytable ORDER BY explode(",", ranks); // But this is not correct.

 

For some reason, I think I should also add the 'list' syntax like I see in this example:

 

$data = "foo:*:1023:1000::/home/foo:/bin/sh";
list($user, $pass, $uid, $gid, $gecos, $home, $shell) = explode(":", $data);
echo $user; // foo
echo $pass; // *

  • 1 year later...

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.