[英]how to insert values from two tables with value in one table is equal to value in the other?
here i have two tables pro_zone_m and temp_const and i am inserting values into third table pro_m where i will be inserting zone from temp_const, and i need to get value of zone_id of corresponding zone from pro_zone_m. 在这里,我有两个表pro_zone_m和temp_const,我正在将值插入到第三表pro_m中,其中我将从temp_const插入zone,并且我需要从pro_zone_m获取相应区域的zone_id值。 i tried but could'nt able to come up with solution.
我尝试过,但无法提出解决方案。
$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);
Update your insert query like this:(assuming zonea_id will store zone_id from temp_const table. 像这样更新您的插入查询:(假设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='$division', product='$product', grade='$grade', potential='$potential', designtn='$designation', mobile='$mobile', primphone='$primary_phone', primemail='$primary_email', exhibition = '$exhibition', zonea_id = (SELECT zone_id FROM temp_const where zone = '$code') "; $ 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.