|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2006-03-08 12:07 UTC] info at newneon dot com
 Description:
------------
I have executed an SQL query with multiple joins (left inners and right outers). When displaying the result set using print_r, I get the following result:
[0] => 10005
    [Respondent] => 5
    [1] => 1
    [Result] => 1
    [2] => 0
    [QuestVersion] => 0
    [3] => CHARLIE
    [MachineID] => CHARLIE
    [4] => 911
    [Enqueteur] => 911
    [5] => Feb 15 2006 12:00AM
    [Datum] => Feb 15 2006 12:00AM
Note the difference between result[0] and result[Respondent]
The proper value is the 10005. How come that PHP converts the 10005 into 5?
Reproduce code:
---------------
Query used:
SELECT * FROM Hoofd LEFT JOIN FillingN ON FillingN.CallCode = Hoofd.Respondent RIGHT OUTER JOIN Hoofd2 ON FillingN.CallCode=Hoofd2.Respondent LEFT JOIN Sample ON FillingN.CallCode=Sample.Code WHERE (Hoofd.Result = 1)
Expected result:
----------------
[0] => 10005
    [Respondent] => 10005
    [1] => 1
    [Result] => 1
Actual result:
--------------
[0] => 10005
    [Respondent] => 5
    [1] => 1
    [Result] => 1
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 02:00:02 2025 UTC | 
Example source: <? $db = mssql_connect("<server>", "<username>", "<password>"); mssql_select_db("<database>", $db); // query goes wrong $query = "SELECT * FROM Hoofd JOIN FillingN ON Hoofd.Respondent = FillingN.CallCode JOIN Hoofd2 ON Hoofd.Respondent=Hoofd2.Respondent JOIN Sample ON Hoofd.Respondent=Sample.Code WHERE (Hoofd.Result = 1) ORDER BY Hoofd.Respondent"; // query below is fine // $query = "SELECT Respondent from Hoofd ORDER BY Respondent"; $res = mssql_query($query, $db); while ($row=mssql_fetch_array($res)) { echo $row['Respondent']."<BR>"; } ?> (Field respondent is int 4)