Jump to content

prob filling mysql table with insert into statement/array


jpk5930

Recommended Posts

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

Archived

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

×
×
  • 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.