jpk5930 Posted November 8, 2009 Share Posted November 8, 2009 I have some stock symbols and info associated with them that I'm trying to insert into a table. I can echo the results of the following code to a webpage to check results, and it shows everything correctly (for example, one symbol may show up multiple times (one row for each date when asking for past 2 weeks)). But when I try to INSERT INTO a table, it only writes the symbols one time each...doesn't show every day between 2 weeks ago and today. The web page displays 74000+ rows, the table captures 7800+ rows. I hope this makes sense?! $sql2="SELECT sym,dat,high,low,vol FROM `main` WHERE dat >= '$targetDate'"; $result2 = mysql_query($sql2); echo "<br />\n"; echo mysql_num_rows($result2); echo "<br />\n"; //Here's where I need to figure out how to write to stocks.P3_1 table. while ($row2 = mysql_fetch_assoc($result2)) { //following 2 lines write to a webpage correctly: //echo $row2["sym"]." ".$row2["dat"]." "$row2["vol"]; //echo "<br />\n"; $sym = $row2["sym"]; $dat = $row2["dat"]; $high = $row2["high"]; $low = $row2["low"]; $vol = $row2["vol"]; $sqlquery2="INSERT INTO P3_1 VALUES('$sym','$dat','$high','$low','$vol')"; mysql_query($sqlquery2) or die ('Error updating database'); } //end while $targetDate works correctly. I know it's my (mis)understanding of PHP and the syntax that I'm not very familiar with. I also know my code is probably ripe with errors, so please be gentle...I'm kinda new to this, trying to learn jk Link to comment https://forums.phpfreaks.com/topic/180772-prob-filling-mysql-table-with-insert-into-statementarray/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.