I
iam_riki
Guest
is there a better way to do the following? I want it to sort the stores by the amount they spend, however, each line in the table is store name and charge ($dollars spent) this was the only way I could come up with, but the sort (both asort and arsort) only sort the first digit (obvious reasons) so how can i get it to sort highest $$ spent with the asscoc store
echo '<p><b><u>STORE RANK ACCORDING TO COST </U></B><p>';
$query = "SELECT tostore, SUM(charge) FROM delivery GROUP BY tostore DESC";
$cnt = 0;
$result = mysql_query($query) or die(mysql_error());
while ($list = mysql_fetch_array($result)){
// WE NEED TO GET THE STORE NAME TO DISPLAY
$id = $list['tostore'];
$storedb = mysql_query("SELECT * FROM stores WHERE id=$id");
$store = mysql_fetch_array($storedb);
$storename = $store['storename'];
$dollars = $list['SUM(charge)'];
//echo "The charge for ".$storename." is $".$dollars."<br>";
$storelist[$cnt]=$dollars.' From '.$storename;
$cnt++;
}
ARsort($storelist);
for($i=0;$i<=count($storelist)-1;$i++){
echo $storelist[$i].'<br>';
}
echo '<p><b><u>STORE RANK ACCORDING TO COST </U></B><p>';
$query = "SELECT tostore, SUM(charge) FROM delivery GROUP BY tostore DESC";
$cnt = 0;
$result = mysql_query($query) or die(mysql_error());
while ($list = mysql_fetch_array($result)){
// WE NEED TO GET THE STORE NAME TO DISPLAY
$id = $list['tostore'];
$storedb = mysql_query("SELECT * FROM stores WHERE id=$id");
$store = mysql_fetch_array($storedb);
$storename = $store['storename'];
$dollars = $list['SUM(charge)'];
//echo "The charge for ".$storename." is $".$dollars."<br>";
$storelist[$cnt]=$dollars.' From '.$storename;
$cnt++;
}
ARsort($storelist);
for($i=0;$i<=count($storelist)-1;$i++){
echo $storelist[$i].'<br>';
}