iceflyin
08-28-2007, 12:18 AM
I'm having trouble with sort(); I can't seem to get it to work...
Now, I just typed this up... Just psedocode, although it *might* actually work! lol! Do I have the right idea? I haven't had any luck getting sort to do anything yet... Do I need to create a multidimensional array or something?
And no, I can't use ASC, or DESC!
//Nearly the exact same as a normal MySQL query, EXCEPT I CANT USE ASC, or DESC!!!!!
$friends = $facebook->api_client->fql_query("SELECT uid, name, pic_square FROM user");
$uids = array();
$names = array();
$pics = array();
foreach ($friends as $friend) {
push($uids, $friend['uid']);
push($names, $friend['name']); //The data is all strings just like a normal name, eg: John Smith
push($pics, $friend['pic_square']);
}
//Now, can I just use this sort to sort the names alphabetically
//and keep the uid's and pics in-line with the name like this?
sort($names,$uids,$pics);
//Now, this should return the three correct
// values for the person with the highest alphabetical name... Eg: Andrew Smith
echo $names[0] . $uids[0] . $pics[0];
//This would return the second, say there was only one person who's name started with a, and one with b.
echo $names[1] . $uids[1] . $pics[1];
//Would return Bart Smith, his uid, and pic.
Now, I just typed this up... Just psedocode, although it *might* actually work! lol! Do I have the right idea? I haven't had any luck getting sort to do anything yet... Do I need to create a multidimensional array or something?
And no, I can't use ASC, or DESC!
//Nearly the exact same as a normal MySQL query, EXCEPT I CANT USE ASC, or DESC!!!!!
$friends = $facebook->api_client->fql_query("SELECT uid, name, pic_square FROM user");
$uids = array();
$names = array();
$pics = array();
foreach ($friends as $friend) {
push($uids, $friend['uid']);
push($names, $friend['name']); //The data is all strings just like a normal name, eg: John Smith
push($pics, $friend['pic_square']);
}
//Now, can I just use this sort to sort the names alphabetically
//and keep the uid's and pics in-line with the name like this?
sort($names,$uids,$pics);
//Now, this should return the three correct
// values for the person with the highest alphabetical name... Eg: Andrew Smith
echo $names[0] . $uids[0] . $pics[0];
//This would return the second, say there was only one person who's name started with a, and one with b.
echo $names[1] . $uids[1] . $pics[1];
//Would return Bart Smith, his uid, and pic.