Jump to content


Photo

error help


  • Please log in to reply
2 replies to this topic

#1 esiason14

esiason14
  • Members
  • PipPipPip
  • Advanced Member
  • 58 posts

Posted 28 July 2006 - 04:39 AM

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! :)

#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 28 July 2006 - 08:08 AM

try

mysql_fetch_assoc
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 28 July 2006 - 11:59 AM

Try changing this:
<?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");
}
?>
to
<?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");
?>

Ken






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users