esiason14 Posted July 28, 2006 Share Posted July 28, 2006 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 https://forums.phpfreaks.com/topic/15854-error-help/ Share on other sites More sharing options...
redarrow Posted July 28, 2006 Share Posted July 28, 2006 try mysql_fetch_assoc Link to comment https://forums.phpfreaks.com/topic/15854-error-help/#findComment-65039 Share on other sites More sharing options...
kenrbnsn Posted July 28, 2006 Share Posted July 28, 2006 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 https://forums.phpfreaks.com/topic/15854-error-help/#findComment-65105 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.