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 ? Link to comment https://forums.phpfreaks.com/topic/59207-mysql-help/ 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? Link to comment https://forums.phpfreaks.com/topic/59207-mysql-help/#findComment-294121 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'... Link to comment https://forums.phpfreaks.com/topic/59207-mysql-help/#findComment-294122 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()); ?> Link to comment https://forums.phpfreaks.com/topic/59207-mysql-help/#findComment-294123 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.