2011-03-24 42 views
0

如何使用另一個查詢將question_text插入到數據庫表中,如下面的代碼所示?如何在已有選擇查詢的文件中使用插入查詢?

mysql_connect ("localhost", "root","") or die ('Error : '.mysql_error()); 
mysql_select_db("keyword"); 
$first_word = current(explode(' ', $_POST['question_text'])); 

$qStuff=mysql_query("SELECT c.field_name,t.category_name, d.domain_name FROM category_fields c, taxonomy_category t, taxonomy_domain d WHERE c.category_id = t.category_id AND t.domain_id = d.domain_id AND c.field_name = '" . mysql_real_escape_string($first_word) . "'"); 
$num_rows = mysql_num_rows($qStuff); 

// some print codes here 
+0

你要插入呢? – Belinda 2011-03-24 09:53:24

+0

你只是這樣做。你有嘗試過什麼嗎? – deceze 2011-03-24 09:53:50

+0

@mario謝謝你的細節:) – fabrik 2011-03-24 09:59:44

回答

0

該插入語句使用select查詢來填充的字段1和字段2的值:

insert into table (field1, field2) 
    select field1, field2 from table2