Hi,
I've been lurking here for a while and recently came up with a problem of my own.
What I am trying to do is get all the amounts from a table, go through them all and count those that have multiples and output the amounts and the number of multiples for each, sorted.
I have this:
<?php
$usr = "airport";
$pwd = "airport";
$db = "airport";
$host = "localhost";
$cid = mysql_connect($host,$usr,$pwd);
mysql_select_db($db);
if(mysql_error()){ print "Database ERROR: " . mysql_error() . "\n"; }
$sql = "SELECT charge FROM deliveries WHERE airlines = 'AccessAir' ";
$result = mysql_query($sql, $cid);
if(mysql_error()){ print "Database ERROR: $sql " . mysql_error(); }
while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
foreach($row as $key => $money){
if($money != 0){
$moneys[] = $money;
}
}
$count = array_count_values($moneys);
array_multisort($moneys, SORT_DESC, SORT_NUMERIC);
$count2 = array_unique($moneys);
foreach($count2 as $key => $value){
echo 'Count:<strong> ' . $value . '</strong> of ammount:<strong> ' . $key . "</strong><br/>\n";
$i++;
}
}
mysql_free_result($result);
mysql_close();
?>
It almost works, just very poorly producing:
Amount 11.00 Count: 0
Amount 11.00 Count: 0
Amount 39.00 Count: 0
Amount 11.00 Count: 1
Amount 39.00 Count: 0
Amount 12.00 Count: 1
Amount 11.00 Count: 2
Amount 39.00 Count: 0
Amount 12.00 Count: 1
Amount 11.00 Count: 2
Amount 100.00 Count: 0
Amount 39.00 Count: 1
Amount 12.00 Count: 2
Amount 11.00 Count: 3
Amount 100.00 Count: 0
Amount 39.00 Count: 1
Amount 12.00 Count: 2
Amount 11.00 Count: 3
Amount 3.00 Count: 6
But in reality there are only 7 amounts, in this order: 11.00, 11.00, 39.00, 12.00, 11.00, 100.00, 3.00.
Where have I gone wrong? I've been working on it for hours and it's given me a head ache. It has to be something stupid and small. Any help or advice on other mistakes is welcomed.