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
https://forums.phpfreaks.com/topic/132935-solved-array_multisort-help/
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 />';
}

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.