Jump to content

[SOLVED] array_multisort help


champoi

Recommended Posts

i'm trying to get values from my mysql and sort it before showing it in the page, but i just cant get the hang of it, this is my code:

 

$listsql = "SELECT * FROM `users_db` WHERE `user_level`='11'";
$listqry = mysql_query($listsql) or die(mysql_error());
$list = mysql_fetch_assoc($listqry);

foreach ($list as $key => $row) {
$comp_name[$key] = $row['comp_name'];
}

array_multisort($comp_name, SORT_ASC, $list);

i just want to sort one set of array (the comp_name) and let the other values along the sorted array to be displayed, but i dont know where it's stored and i get problems when using the while() when displaying the values, does anyone have a better option than this? or im doing things incorrectly? HELP!  ???

Link to comment
Share on other sites

I think I know what you're trying to do, try the code bellow in place of yours. You can sort your results in the mysql_query;

 

$listsql = "SELECT comp_name FROM `users_db` WHERE `user_level`='11' ORDER BY comp_name ASC";
$listqry = mysql_query($listsql) or die(mysql_error());
while($list = mysql_fetch_array($listqry)){
echo $list['comp_name'].'<br />';
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.