This started as a problem with a SELECT statement that has evolved into a problem with sorting an array...
The original Thread on the Database fora, if you would like to check it out is here:
http://www.phpbuilder.com/board/showthread.php?s=&threadid=10278121
The current problem is using multi-sort to sort an array that was built using several SQL statements over two while construncts:
$alphanum = $db->sql_numrows($alpharesult = $db->sql_query("SELECT countryname,countrynum,max(date)
AS date FROM ".$prefix."_".$table."
GROUP BY countryname,countrynum"));
$alpharow = mysql_fetch_array($alpharesult);
$a = 0;
while ($a < $alphanum) {
$alphalist[$a]['countryname'] = mysql_result($alpharesult,$a,"countryname");
$alphalist[$a]['countrynum'] = mysql_result($alpharesult,$a,"countrynum");
$alphalist[$a]['date'] = mysql_result($alpharesult,$a,"date");
$a++;
}
$b = 0;
while ($b < $alphanum) {
$countryname = $alphalist[$b]['countryname'];
$countrynum = $alphalist[$b]['countrynum'];
$date = $alphalist[$b]['date'];
$betaresult = $db->sql_query("SELECT * FROM ".$prefix."_".$table." WHERE date=$date");
$alphalist[$b]['troops'] = mysql_result($betaresult,0,"troops");
$b++;
}
// this little piece of code is from
[url]http://www.php.net/manual/en/functi...y-multisort.php[/url] I was having trouble with my sort and thought it might help.
foreach ($alphalist as $key => $row) {
$countryname[$key] = $row["countryname"];
$countrynum[$key] = $row["countrynum"];
$date[$key] = $row["date"];
$troops[$key] = $row["troops"];
}
array_multisort($troops, SORT_DESC);
I have used the print_r() function to verify that $alphalist does in fact contain the correct information... I now just need to get it to sort by "troops" DESC and I'm done. Any help as to what is causing the problem would be greatly appreciated.
Thanks.