Thanks for reading this
I have this function that based on the local currency of the user ($currency_to) and currency the data is being quoted in, currently fixed as CNY ($currency_from), uses the yahoo finance currency calculator to take a number ($figure) and spit back either:
a) The value in the currency it is being displayed in
Code:
return round($exchange_rate*$figure, -1) . ' ' . $currency_to;
or
b) if the value is quoted as 0 or nothing (null) it supposed to notify the user that its not applicable
The problem is that it does not care if the value is 0 or null, it just gives the value in the (a) format i.e. 0 USD
Here is the function:
Code:
<?php
function display_price ($currency_from, $currency_to,$figure ) {
$url = "http://quote.yahoo.com/d/quotes.csv?s="
. $currency_from . $currency_to . "=X"
. "&f=l1&e=.csv";
$open = fopen($url, "r");
$exchange_rate = fread($open, 2000);
fclose($open);
if ($exchange_rate == "0.00")
$exchange_rate = "1";
else
$error = "sorry, we could not determine your location and display the prices in your local area,";
if ($figure=="null")
return "N/A";
else if ($figure=="0")
return "N/A";
else
return round($exchange_rate*$figure, -1) . ' ' . $currency_to;
}
$currency_from="CNY";?>
Also including the bit where it is being spat back, though I am pretty sure the problem is with the function.
Code:
<?php
mysql_connect($server,$user,$password);
@mysql_select_db($database) or die("Sorry, unable to select database");
$result = mysql_query("SELECT * FROM drup_content_type_school ORDER BY field_schoolname_value");
$i=0;
while($row = mysql_fetch_array($result))
{
if ($i % 2)
$class= "tr3";
else
$class= "tr2";
echo "<tr class='" . $class . "'>
<td class='td1'><a href='http://compare-chineselanguageschools.com/content/output-school?school=" . $row[field_schoolname_value] . "'>" . $row['field_schoolname_value'] . "</a></td>
<td class='td2'>" . $row['field_est_value'] . "</td>
<td class='td3'>" . $row['field_max_class_size_value'] . "</td>
<td class='td1'>" . display_price($currency_from, $currency_to, $row[$price]) . "</td>
<td class='td1'>" . $row['field_max_class_size_value'] . "</td>
</tr>
";
$i++;
}
?>
Thank you so much for any input.
|