Hey all!
I've come across a little thing which I'm trying to work out the best/most efficient way of doing.. or then again, just how to do it to begin with!
Basically what I'm doing is pulling a load of member ID's from a mysql table, which I then use to return the respective username from another table. However these output from my while (mysql_fetch_array) loop in order of the ID ordered ASC.
What I want to do, is reorder the output so that they are printed out by the username, alphabetically.. but I also need to keep the user ID for use on the page.
I just tried to have 2 parallel arrays, both numerically referenced, so I could do a for loop for 0 to count(array_length).. but obviously if I used sort($nameArray) this would put the reference numbers out of sync..
So, my question is how can I do this?
This is basically the code I have so far, with my attempts removed because they are just silly! I think I somehow need to put them into another array, then sort() it.. but I'm not sure how to keep both values (ID and name) in the array..
<?php
$sql = sprintf("SELECT * FROM %s WHERE group_id = %s ORDER user_id ASC", DB_USER_GROUP_MEMBERS, $_GET['id']);
$group_query = mysql_query($sql);
while( $group = mysql_fetch_array($group_query) ) {
$id = $group['user_id'];
$name = dbFieldReturn("user", DB_USERS, "id", $group['user_id']);
}
//sort($group_array);
for($k=0; $k<count($group_array); $k++) {
?>
<option value="<?php echo //ID; ?>"><?php echo //name; ?></option>
<?php
}
?>