Crew-Portal Posted November 12, 2007 Share Posted November 12, 2007 Is there any simple way to take a array and punch in into a mysql query or am I going to have to insert each array by itself? Quote Link to comment Share on other sites More sharing options...
revraz Posted November 12, 2007 Share Posted November 12, 2007 Give us an example of what you are trying to do. You can do pretty much anything with an Array and MySQL Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 12, 2007 Share Posted November 12, 2007 if your array keys are same as your mysql field names it would be easy eg. or you have the same length of array elements as your mysql table consider the following code $arrData = array("username"=>"rajivgonsalves", "password"=>"somepassword", "location"=>"India"); $sqlQuery = "insert into $tablename (".implode(",",array_keys($arrData))." VALUES ('".implode("','",array_values($arrData))."'"; echo $sqlQuery; $sqlQuery = "insert into $tablename VALUES ('".implode("','",array_values($arrData))."'"; echo $sqlQuery; Quote Link to comment Share on other sites More sharing options...
Pavel11 Posted November 12, 2007 Share Posted November 12, 2007 If you want save a array in database you may serialise (http://www.php.net/manual/ru/function.serialize.php) it and save as string. For restore a array you must unserialise it. But if you use this way you can't operate with certain elements of array in database(select, update, etc.) 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.