<?
/*
//use for debugging
$data[] = array ("product"=>"prod1", "price"=>15, "currency"=>"USD");
$data[] = array ("product"=>"prod2", "price"=>50, "currency"=>"EUR");
$data[] = array ("product"=>"prod3", "price"=>22, "currency"=>"GBP");
$data[] = array ("product"=>"prod4", "price"=>30, "currency"=>"YEN");
*/
$tablename = "";
$sql = "Select product, price, currency from $tablename";// enter sql query here
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)) //create an array of arrays by cycling through the recordset
{
$results_array[] = $row;
}
// convert the amounts into common currency
for ($i=0; $i<count($results_array); $i++) //iterate through the array and convert to common currency
{
$results_array[$i]['price'] ==converttoeuros($results_array[$i]['price'], $results_array[$i]['currency']); //assume the currency conversion function takes two vars: the amount and the input currency
$results_array[$i]['currency'] = "EUR"; //assuming everything converted to euros this would be a sensible additional step to avoid later confusion
}
// now all is converted
// sort and display
*/
foreach ($results_array as $key => $val) {
$price[$key] = $val['price'];
$currency[$key] = $val['currency']; //the currency code is a bit redundant here as you have already moved everything to a common currency
$product[$key] = $val['product'];
}
// Sort the data with price ascending
// Add $data as the last parameter, to sort by the common key
array_multisort($price, SORT_ASC, $currency, SORT_DESC, $product, SORT_ASC, $results_array);
print_r($results_array);
?>