jd2007 Posted July 10, 2007 Share Posted July 10, 2007 how do i add an array into a MySQL table in the database ? for example i want to add array (below) into a table named 'fruits'.. fruit=array("orange", "apple", "mango", "banana", "papaya", "lemon"); i want to add it into the table 'fruits' and automatically assign it a id ? Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted July 10, 2007 Share Posted July 10, 2007 is each value its own field or its own row? Quote Link to comment Share on other sites More sharing options...
jd2007 Posted July 10, 2007 Author Share Posted July 10, 2007 i want to add it into a column 'myfruits'... Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted July 10, 2007 Share Posted July 10, 2007 didn't exaclty answer it but try this <?php foreach ($fruits as $value){ mysql_query(INSERT INTO `mytable` (myfruits) VALUES ($value)) or die(mysql_error()); } ?> you might be able to (untested) to try <?php mysql_query(INSERT INTO `mytable` (myfruits) VALUES($fruit)) or die(mysql_error()); ?> 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.