PHP LOOP from database and save into one field

I need some help.

I have table one with field code and table two with field code_two.

record from table_one :

----code----
32
23
34
25
------------

and send to table_two like this

----code_two-----
32,23,34,25.
-----------------

I wanna send record from table one field 'code' into table two field code_two.

Here my php loop input box

foreach($_POST['code'] as $cnt => $qty) {|
    mysql_query("insert into table_two values('$code_from_table_one');
}

is that loop in query is work? i tried and getting error, little help please :( thanks

Answers


Don't need to use PHP for it you can do it with GROUP_CONCAT() in MySQL

INSERT INTO code_two SELECT GROUP_CONCAT(`code` SEPARATOR ',') FROM code

More on http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_group-concat


Need Your Help

Single database tool to access different database types?

mysql database postgresql derby

I’d like a visual database tool that will allow me to access multiple database types from the same program. I’m looking for anything that supports Mysql, PostgreSQL, and Derby. Anything else it sup...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.