Jump to content

Insert data into database, possible to use array?


Recommended Posts

I have a basic inserting data question.


Here's my code:

for($i = 0; $i < $j; $i++){
$query = "INSERT INTO weather VALUES ('$snowdata[$i][0]','$snowdata[$i][1]','$snowdata[$i][2]','$snowdata[$i][3]','$snowdata[$i][4]',


First off, it doesn't work because I assume the snowdata matrices aren't being evaluated?  Or is there something else obvious I'm missing?  Second off, is it some how possible to insert an array (or row of a matrix) directly into a row of an sql database?  Thanks for any pointers or leads.



Link to comment
Share on other sites

What is the value of $j ? - maybe use sizeof($snowdata) instead, depending on application.


Consider something like this, for the fun factor:


for ($i = 0; $i < sizeof($snowdata); $i++)
     $query = "INSERT INTO weather VALUES (";

     for ($n = 1; $n <= 14; $n++) $query .= "'{$snowdata[$i][$n]}',";

     $db->query($query = substr($query, 0, strlen($query) - 1).")");

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

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

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.