Note that there are some explanatory texts on larger screens.

plurals
  1. POMySQL query work OK in Workbench but slightly different in PHP
    text
    copied!<p>I have this MySQL query that works fine in MySQL environment, but when run in PHP doesn't because it shows the same value for REGION, PROVINCIA, COMUNA in every case (record), instead of the right ones belonging to each independent record, as they may differ from one to the other.</p> <p>I need to find the proper SQL statement to query in such a way that allow me to get the actual REGION, PROVINCIA, COMUNA of every record (3) involved in the query.</p> <p>Records on tables pos1postul, pos2pad and pos3mad are referencing tables dir_region, dir_provincia and dir_comuna through fields REGION_ID, PROVINCIA_ID, COMUNA_ID.</p> <p>Any help will be much appreciated.</p> <pre><code>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 </code></pre> <p>PHP Code:</p> <pre><code>$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); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload