我有這樣的MySQL查詢是在MySQL環境中工作正常,但在PHP中運行時不會因爲它顯示區相同的值,PROVINCIA,COMUNA在任何情況下(記錄),而不是屬於每個獨立記錄,因爲它們可能從一個到另一個不同是正確的。MySQL查詢工作,工作臺確定的,但在PHP
我需要找到合適的SQL語句來進行查詢,以便讓我得到查詢中涉及的每個記錄(3)的實際REGION,PROVINCIA,COMUNA。
表pos1postul,pos2pad和pos3mad上的記錄通過字段REGION_ID,PROVINCIA_ID和COMUNA_ID引用表dir_region,dir_provincia和dir_comuna。
任何幫助將不勝感激。
SELECT * FROM db3.pos1postul
INNER JOIN db3.dir_region AS region1 ON pos1postul.pos1_region=region1.REGION_ID
INNER JOIN db3.dir_provincia AS provincia1 ON pos1postul.pos1_prov=provincia1.PROVINCIA_ID
INNER JOIN db3.dir_comuna AS comuna1 ON pos1postul.pos1_comu=comuna1.COMUNA_ID, db3.pos2pad
INNER JOIN db3.dir_region AS region2 ON pos2pad.pos2_regionpad=region2.REGION_ID
INNER JOIN db3.dir_provincia AS provincia2 ON pos2pad.pos2_provpad=provincia2.PROVINCIA_ID
INNER JOIN db3.dir_comuna AS comuna2 ON pos2pad.pos2_comupad=comuna2.COMUNA_ID, db3.pos3mad
INNER JOIN db3.dir_region AS region3 ON pos3mad.pos3_regionmad=region3.REGION_ID
INNER JOIN db3.dir_provincia AS provincia3 ON pos3mad.pos3_provmad=provincia3.PROVINCIA_ID
INNER JOIN db3.dir_comuna AS comuna3 ON pos3mad.pos3_comumad=comuna3.COMUNA_ID
WHERE pos1_aluID='n'
AND pos2_padID=pos1_IDpostulpad
AND pos3_madID=pos1_IDpostulmad
PHP代碼:
$idpostul_rsPostul = "-1";
if (isset($idpostul)) {
$idpostul_rsPostul = $idpostul;
}
mysql_select_db($database_conndb3, $conndb3);
$query_rsPostul = sprintf("SELECT * FROM db3.pos1postul INNER JOIN db3.dir_region AS region1 ON pos1postul.pos1_region=region1.REGION_ID INNER JOIN db3.dir_provincia AS provincia1 ON pos1postul.pos1_prov=provincia1.PROVINCIA_ID INNER JOIN db3.dir_comuna AS comuna1 ON pos1postul.pos1_comu=comuna1.COMUNA_ID, db3.pos2pad INNER JOIN db3.dir_region AS region2 ON pos2pad.pos2_regionpad=region2.REGION_ID INNER JOIN db3.dir_provincia AS provincia2 ON pos2pad.pos2_provpad=provincia2.PROVINCIA_ID INNER JOIN db3.dir_comuna AS comuna2 ON pos2pad.pos2_comupad=comuna2.COMUNA_ID, db3.pos3mad INNER JOIN db3.dir_region AS region3 ON pos3mad.pos3_regionmad=region3.REGION_ID INNER JOIN db3.dir_provincia AS provincia3 ON pos3mad.pos3_provmad=provincia3.PROVINCIA_ID INNER JOIN db3.dir_comuna AS comuna3 ON pos3mad.pos3_comumad=comuna3.COMUNA_ID WHERE pos1_aluID=%s AND pos2_padID=pos1_IDpostulpad AND pos3_madID=pos1_IDpostulmad", GetSQLValueString($idpostul_rsPostul, "int"));
$rsPostul = mysql_query($query_rsPostul, $conndb3) or die(mysql_error());
$row_rsPostul = mysql_fetch_assoc($rsPostul);
請出示你的PHP代碼。 – Pang
嗨龐,只是添加了PHP代碼。 – Isavma