1

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 want to 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.

1
  • You could take all the values from the first query into an array and use the implode() function, that way you only need to run one insert. Commented Sep 26, 2014 at 10:09

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

simple solutions are the best :) my friend

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.