What I'm trying to do is read a csv file and insert it into my db. I find all of the ticker symbols from the db...then for each one I want to loop through and insert the values from the csv file where the ticker_symbols are the same. Since the symbol is not included in the file, I add the symbol to the array ( $arr[] = $value๐.
Anyway, the insert works for only the first symbol and then I get the following error:
Warning: Supplied argument is not a valid MySQL result resource in c:\apache\htdocs\stocks\insert.php on line 25
Line 25 is
while ($ticker = mysql_fetch_array($result))
Code
$sql3 = "SELECT ticker_symbol from stocks order by ticker_symbol";
if (!$result = mysql_query($sql3))
{
die("Could not get the the ticker symbols: " . mysql_error() . "<br />\n");
}
while ($ticker = mysql_fetch_array($result))
{
foreach ($ticker as $value)
{
$fcontents = file ('http://www.adomain.com/table.csv?s='.$value.'&a=02&b=13&c=1986&d=06&e=28&f=2008&g=d&ignore=.csv');
for($i=0; $i<sizeof($fcontents); $i++)
{
$line = trim($fcontents[$i]);
$arr = explode(",", $line);
$arr[] = $value;
$sql = "insert into historical_quotes values ('".
implode("','", $arr) ."')";
mysql_query($sql);
echo $sql ."<br>\n";
if(mysql_error())
{
echo mysql_error() ."<br>\n";
}
}
}
Please enlighten me! ๐