次のような MySQL クエリがあります。
SELECT cp.plan_name, cp.plan_time FROM courses c
INNER JOIN course_to_plan cpl ON cpl.course_id = c.course_id
INNER JOIN courseplans cp ON cp.plan_id = cpl.plan_id
WHERE cpl.course_id = '$course_id';
これにより、たとえば次のようなデータが出力されます。
+----------------------------+-----------+
| plan_name | plan_time |
+----------------------------+-----------+
| Plan number one name | 6 |
| Plan number two name | 6 |
| Plan number three name | 10 |
+----------------------------+-----------+
これらの行をフォーム送信時に新しいテーブルに挿入したいと考えています。
update.php
テーブルに値を挿入するようにコーディングを続けるにはどうすればよいnewtable
ですか?
if (isset($_POST['submit'])) {
$course_id = $_POST['course_id'];
$course_result = mysql_query
("SELECT cp.plan_name, cp.plan_time FROM courses c
INNER JOIN course_to_plan cpl ON cpl.course_id = c.course_id
INNER JOIN courseplans cp ON cp.plan_id = cpl.plan_id
WHERE cpl.course_id = '$course_id'");
/* I want the result of the above rows to be inserted in the table
newtable which has the columns plan_name, plan_time */
私は PHP と MySQL でまったく役に立たないことを認めたくありませんが、学ぼうとしています。結果を格納するためにある種の配列を作成し、挿入をループする必要があると思いますが、方法がわかりません。