cmor Posted July 27, 2007 Share Posted July 27, 2007 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]', '$snowdata[$i][5]','$snowdata[$i][6]','$snowdata[$i][7]','$snowdata[$i][8]','$snowdata[$i][9]','$snowdata[$i][10]','$snowdata[$i][11]','$snowdata[$i][12]', '$snowdata[$i][13]','$snowdata[$i][14]')"; $db->query($query); } 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. -Chris Quote Link to comment Share on other sites More sharing options...
Illusion Posted July 27, 2007 Share Posted July 27, 2007 If u r matrix elements are not interpreted then try this ................VALUES ('{$snowdata['$i'][0]}','{$snowdata['$i'][1]}',............................ Quote Link to comment Share on other sites More sharing options...
bubblegum.anarchy Posted July 27, 2007 Share Posted July 27, 2007 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).")"); } Quote Link to comment Share on other sites More sharing options...
Barand Posted July 27, 2007 Share Posted July 27, 2007 or <?php $query = "INSERT INTO weather VALUES ('" . join ("','", $snowdata[$i]) . "')"; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.