creating and reading from an 'array'
Posted: Tue May 29, 2012 12:12 am
i have a table1 with a set of tasks
group task
2 research
2 analyze
3 review
3 write
3 report
what i want to do is write a query that says something like this:
"insert into [table2] each task from [table1] where the group number is 2"
so the result of the query will show table2 looking like this:
id task
1 research
2 analyze
the way i have been doing it is hard coding:
so i need to pull each record from table 1, list it as a separate item to be placed into table2, and then group them into a text string and place that in table3.
group task
2 research
2 analyze
3 review
3 write
3 report
what i want to do is write a query that says something like this:
"insert into [table2] each task from [table1] where the group number is 2"
so the result of the query will show table2 looking like this:
id task
1 research
2 analyze
the way i have been doing it is hard coding:
Code: Select all
$task1 = 'research';
$task2 = 'analyze';
$task_bundle = $task1 . '; ' . $task2;
$query1 = "INSERT INTO table2 (group, task) VALUES ('$group','$task1')";
mysql_query($query1);
$query2 = "INSERT INTO table2 (group, task) VALUES ('$group','$task2')";
mysql_query($query2);
$query3 = "INSERT INTO table3 (task_bundle) VALUES ('$task_bundle')";
mysql_query($query3);