Using multiple fopen or multiple fgetcsv
Posted: Wed Nov 04, 2009 5:34 am
I am trying to read two csv files on the same page so that I can display the data from then on the page. But I only ever seem to see the data from the first file???
And the full page
Code: Select all
<?php
$file_oil = fopen("http://download.finance.yahoo.com/d/quotes.csv?s=CLZ09.NYM&f=sl1d1t1c1ohgv&e=.csv", "r");
while (!feof($file_oil) )
{
$oil_text = fgetcsv($file_oil, 1024);
}
fclose($file_oil);
$file_gold = fopen("http://download.finance.yahoo.com/d/quotes.csv?s=GCX09.CMX&f=sl1d1t1c1ohgv&e=.csv", "r");
while (!feof($file_gold) )
{
$gold_text = fgetcsv($file_gold, 1024);
}
fclose($file_gold);
?>Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<?php
$file_oil = fopen("http://download.finance.yahoo.com/d/quotes.csv?s=CLZ09.NYM&f=sl1d1t1c1ohgv&e=.csv", "r");
while (!feof($file_oil) )
{
$oil_text = fgetcsv($file_oil, 1024);
}
fclose($file_oil);
$file_gold = fopen("http://download.finance.yahoo.com/d/quotes.csv?s=GCX09.CMX&f=sl1d1t1c1ohgv&e=.csv", "r");
while (!feof($file_gold) )
{
$gold_text = fgetcsv($file_gold, 1024);
}
fclose($file_gold);
?>
</head>
<body><table border="0"><tbody>
<tr style="text-align: center;">
<td>Oil Price <?php print $oil_text[1]; ?></td>
<td>Gold Price <?php print $gold_text[1]; ?></td>
</tr>
<tr>
<td><img src="http://www.oil-price.net/1q_small.gif" alt="Oil Prices for the Last Quarter" width="200" height="110" /></td>
<td><img src="http://www.gold-quote.net/1q_small.gif" alt="Gold Prices for the Last Quarter" width="200" height="110" /></td>
</tr>
</tbody></table>
</body>
</html>