Jump to content

Archived

This topic is now archived and is closed to further replies.

esiason14

error help

Recommended Posts

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:

[CODE]Warning: Supplied argument is not a valid MySQL result resource in c:\apache\htdocs\stocks\insert.php on line 25[/CODE]

Line 25 is [CODE]while ($ticker = mysql_fetch_array($result))[/CODE]

Code

[code=php:0]$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";
        }
      }
  }[/code]

Please enlighten me! :)

Share this post


Link to post
Share on other sites
Try changing this:
[code]<?php
$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");
}
?>[/code]
to
[code]<?php
$sql3 = "SELECT ticker_symbol from stocks order by ticker_symbol";
$result = mysql_query($sql3) or die("Could not get the the ticker symbols: " . mysql_error() . "<br />\n");
?>[/code]

Ken

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.