[英]how to insert into two tables; one will insert 1 row and the other one will insert multiple rows, the two tables has one column with the same value
[英]how to insert values from two tables with value in one table is equal to value in the other?
在這里,我有兩個表pro_zone_m和temp_const,我正在將值插入到第三表pro_m中,其中我將從temp_const插入zone,並且我需要從pro_zone_m獲取相應區域的zone_id值。 我嘗試過,但無法提出解決方案。
$uisq = "SELECT * FROM pro_zone_m";
$ytu = mysql_query($uisq);
$mnm = mysql_fetch_array($ytu);
extract($mnm);
$wqr = "SELECT * FROM temp_const";
$wqe = mysql_query($wqr);
while($wqe1 = mysql_fetch_array($wqe))
{
extract($wqe1);
$zxc = "INSERT INTO pro_m set custid='$custid', firstname='$firstname', lastname='$lastname', country='$country',
city='$city', state='$state', zone='$zone', adresstype='$address_type', address1='$address1', address2='$address2',category='$category',
focus='$focus', assignto='$assign_to', division='$division', product='$product', grade='$grade', potential='$potential', designtn='$designation',
mobile='$mobile', primphone='$primary_phone', primemail='$primary_email',
exhibition = '$exhibition', zonea_id = '$zoneid' WHERE zone = '$code' ";
$zxc1 = mysql_query($zxc);
像這樣更新您的插入查詢:(假設zonea_id將存儲temp_const表中的zone_id。
$ zxc =“ INSERT INTO pro_m set custid ='$ custid',firstname ='$ firstname',lastname ='$ lastname',country ='$ country',city ='$ city',state ='$ state', zone ='$ zone',adresstype ='$ address_type',address1 ='$ address1',address2 ='$ address2',category ='$ category',focus ='$ focus',Assignto ='$ assign_to',除法='$ division',產品='$ product',等級='$ grade',潛力='$ potential',designtn ='$ designation',mobile ='$ mobile',primphone ='$ primary_phone',primemail = ''$ primary_email',展覽='$ exhibition', zonea_id =(從temp_const中選擇zone_id,其中zone ='$ code') ”;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.