Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP Array with Key Values don't match
    primarykey
    data
    text
    <p>I have a query that I'm running in php. The DB is SQL Server 2008. The query in PHP is: </p> <pre><code>"SELECT * FROM applicants WHERE applicants.families_id = '{$family_array['id']}'"; </code></pre> <p>Where the <code>$family_array</code> id is matched against the <code>families_id</code>. I get a single row as a result. I save that row to an array in PHP by using the <code>mssql_fetch_array</code> function. When I print this array I get the following:</p> <pre><code> Array ( [0] =&gt; 26 [id] =&gt; 21 [1] =&gt; 21 [user_id] =&gt; 21 [2] =&gt; Kristi [mother_fname] =&gt; Kristi [3] =&gt; Lochala [mother_lname] =&gt; Lochala [4] =&gt; Nathan [father_fname] =&gt; Nathan [5] =&gt; Lochala [father_lname] =&gt; Lochala [6] =&gt; [app_emergency] =&gt; [7] =&gt; [upload_mother_passport] =&gt; [8] =&gt; [upload_mother_visa] =&gt; [9] =&gt; [upload_father_passport] =&gt; [10] =&gt; 0 [upload_father_visa] =&gt; 0 [11] =&gt; nathan-lochala [user_added_username] =&gt; nathan-lochala [12] =&gt; Mar 19 2013 01:00:37:660PM [user_added_date] =&gt; Mar 19 2013 08:48:00:000AM [13] =&gt; 192.168.88.15 [user_added_ip] =&gt; 192.168.88.15 [14] =&gt; [user_updated_username] =&gt; [15] =&gt; [user_updated_date] =&gt; [16] =&gt; [user_updated_ip] =&gt; [17] =&gt; 21 [18] =&gt; nathan-lochala [username] =&gt; nathan-lochala [19] =&gt; b9a234cb37ce2b75d77befecabfa650e39489e0b [hash_password] =&gt; b9a234cb37ce2b75d77befecabfa650e39489e0b [20] =&gt; Nathan [fname] =&gt; Nathan [21] =&gt; Lochala [lname] =&gt; Lochala [22] =&gt; 2 [num_child] =&gt; 2 [23] =&gt; Mar 19 2013 08:48:00:000AM [24] =&gt; 192.168.88.15 [25] =&gt; [26] =&gt; [27] =&gt; nathan-lochala@shk.qsi.org [email] =&gt; nathan-lochala@shk.qsi.org [28] =&gt; parent [access] =&gt; parent ) </code></pre> <p>If you notice, the <code>index [0]</code> does not match the corresponding key value <code>[id]</code>. Why is this? I've ran the exact same query using the SQL Server Manager and it performs as expected, but when I fetch that array in PHP only the first key value gets skewed. I've tried everything I can think of short of recreating the table. Any ideas?</p> <p>EDIT: Running mssql_fetch_assoc() gives me the following results:</p> <pre><code>Array ( [id] =&gt; 21 [user_id] =&gt; 21 [mother_fname] =&gt; Kristi </code></pre> <p><img src="https://i.stack.imgur.com/WUQ95.png" alt="enter image description here"></p> <p><img src="https://i.stack.imgur.com/IGcPK.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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