views:

59

answers:

1

How would I do this (the part in square brackets):

$name = 'Bob';

mysql_query("INSERT INTO table(field1,field2) 
[ select value of field1 from another table ], '$name'");
+5  A: 

The SQL part of it might look like this:

INSERT INTO table1 (field1, field2) SELECT field1, 'Bob' FROM table2 WHERE ...

Dynamically constructing that in PHP is a simple exercise I leave up to the reader :)

Asaph