Jump to content

error help


esiason14

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! :)
Link to comment
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.