I have three arrays. One that contains the given title information from the user stored in $attributenames. The second has the data from the user stored in $anesdata. (So the first two are related) And the third is a dictionary so that I can get out the information I want using the index which is stored in $medicalInstanceDictionary.
This is the first one:
Array
(
[0] => PATIENT MRN
[1] => PATIENT LAST NAME
[2] => PATIENT FIRST NAME
[3] => PATIENT MIDDLE NAME
[4] => PATIENT SSN
[5] => PATIENT SEX
[6] => INVOICE
[7] => TRANSACTION
[8] => DATE OF PROCEDURE
[9] => POSTING DATE
[10] => LOCATION
[11] => CHARGE AMT
[12] => PROVIDER
[13] => FSC1
[14] => FSC2
[15] => PATIENT DOB
[16] => ATTENDING SURGEON
[17] => ATTENDING SURGEON
[18] => CPT CODES
[19] => ASA CLASSFICATION
[20] => ANESTHESIA CRNA
[21] => ANESTHESIA RESIDENT
[22] => SURGERY START TIME
[23] => SURGERY END TIME
[24] => SVC UNIT
[25] => FACILITY NAME
[26] => BILLING NUMBER
[27] => BILLING AREA NAME
[28] => PROCEDURE MODIFIER1
[29] => PROCEDURE MODIFIER2
[30] => PROCEDURE MODIFIER3
[31] => PRIMARY DX
[32] => SECONDARY DX
)
The second array is a two dimensional array, but each line is equivalent to one patient. So that first patient looks like this(put in x's instead of actual patient data):
[0] => Array
(
[0] => xxxx
[1] => xxxx
[2] => xxxx
[3] => xxxx
[4] => xxxxx
[5] => xxxx
[6] => xxxx
[7] => xxx
[8] => xxxxx
[9] => xxxx
[10] => xxxx
[11] => xxxxx
[12] => xxxx
[13] => xxxxx
[14] => xxxx
[15] => xxxx
[16] => xxxxxxx
[17] => xxxxx
[18] => xxxxx
[19] => xxxx
[20] =>
[21] => xxxxx
[22] => xxxxx
[23] => xxxxx
[24] => xxxxx
[25] => xxxx
[26] => xxxxx
[27] => xxxx
[28] => xxxxxxxx
[29] => xxxx
[30] =>
[31] => xxxxxxx
[32] => xxxxxxx
)
Then the dictionary looks like this:
$medicalInstanceDictionary = array(
'CPT CODES' => "CPT_Code",
'ASA CLASSFICATION' => "MG_ASA_Class",
'FACILITY NAME' => "Facility_Name",
'BILLING NUMBER' => "Billing_Number",
'BILLING AREA NAME' => "Billing_Area_Name",
'PROCEDURE MODIFIER1' => "Procedure_Modifier1",
'PROCEDURE MODIFIER2' => "Procedure_Modifier2",
'PRIMARY DX' => "Primary_Dx",
'SECONDARY DX' => "Secondary_Dx",
'INVOICE' => "FIN"
);
I am doing a nested foreach loop to get each row.
foreach ($dataarray as $dataindex => $datavalue)
{
$out = "";
foreach ($dictionary as $index => $value)
{
//find PATIENT MRN in $attributearray and get it's index
$attributeindex = array_search($index, $attributearray);
if ($attributeindex===FALSE) {
echo "Error : ".$index." not found <br />";
} else {
echo "<br>The attribute is: ".$value." The index is: ".$attributeindex."<br>";
}
(more code....)
}
(more code....)
}
That echo statement looks like this:
The attribute is: CPT_Code The index is: 18
The attribute is: MG_ASA_Class The index is: 19
The attribute is: Facility_Name The index is: 25
The attribute is: Billing_Number The index is: 26
The attribute is: Billing_Area_Name The index is: 27
The attribute is: Procedure_Modifier1 The index is: 28
The attribute is: Procedure_Modifier2 The index is: 29
The attribute is: Primary_Dx The index is: 31
Error : SECONDARY DX not found
The attribute is: FIN The index is: 6
I have no idea why it is skipping over Secondary_Dx. I have checked for spelling errors. I don't think it is my method of doing it because it only does not work for Secondary_Dx. The only thing I can think of is that it does something funky since it is the last element of the array. Has anyone seen this before?
Edit:
Added element(tried both methods, and both resulted in the same looking array using print_r:
//array_push($attributenames, "THE END");
$attributenames[] ="THE END";
echo "<pre>";
print_r($attributenames);
echo "</pre>";
output from that along with the error handling statement from above:
Array
(
[0] => PATIENT MRN
[1] => PATIENT LAST NAME
[2] => PATIENT FIRST NAME
[3] => PATIENT MIDDLE NAME
[4] => PATIENT SSN
[5] => PATIENT SEX
[6] => INVOICE
[7] => TRANSACTION
[8] => DATE OF PROCEDURE
[9] => POSTING DATE
[10] => LOCATION
[11] => CHARGE AMT
[12] => PROVIDER
[13] => FSC1
[14] => FSC2
[15] => PATIENT DOB
[16] => ATTENDING SURGEON
[17] => ATTENDING SURGEON
[18] => CPT CODES
[19] => ASA CLASSFICATION
[20] => ANESTHESIA CRNA
[21] => ANESTHESIA RESIDENT
[22] => SURGERY START TIME
[23] => SURGERY END TIME
[24] => SVC UNIT
[25] => FACILITY NAME
[26] => BILLING NUMBER
[27] => BILLING AREA NAME
[28] => PROCEDURE MODIFIER1
[29] => PROCEDURE MODIFIER2
[30] => PROCEDURE MODIFIER3
[31] => PRIMARY DX
[32] => SECONDARY DX
[33] => THE END
)
This is dictionary array Array
(
[CPT CODES] => CPT_Code
[ASA CLASSFICATION] => MG_ASA_Class
[FACILITY NAME] => Facility_Name
[BILLING NUMBER] => Billing_Number
[BILLING AREA NAME] => Billing_Area_Name
[PROCEDURE MODIFIER1] => Procedure_Modifier1
[PROCEDURE MODIFIER2] => Procedure_Modifier2
[PRIMARY DX] => Primary_Dx
[SECONDARY DX] => Secondary_Dx
[INVOICE] => FIN
)
The attribute is: CPT_Code The index is: 18
The attribute is: MG_ASA_Class The index is: 19
The attribute is: Facility_Name The index is: 25
The attribute is: Billing_Number The index is: 26
The attribute is: Billing_Area_Name The index is: 27
The attribute is: Procedure_Modifier1 The index is: 28
The attribute is: Procedure_Modifier2 The index is: 29
The attribute is: Primary_Dx The index is: 31
Error : SECONDARY DX not found
Array ( [0] => PATIENT MRN [1] => PATIENT LAST NAME [2] => PATIENT FIRST NAME [3] => PATIENT MIDDLE NAME [4] => PATIENT SSN [5] => PATIENT SEX [6] => INVOICE [7] => TRANSACTION [8] => DATE OF PROCEDURE [9] => POSTING DATE [10] => LOCATION [11] => CHARGE AMT [12] => PROVIDER [13] => FSC1 [14] => FSC2 [15] => PATIENT DOB [16] => ATTENDING SURGEON [17] => ATTENDING SURGEON [18] => CPT CODES [19] => ASA CLASSFICATION [20] => ANESTHESIA CRNA [21] => ANESTHESIA RESIDENT [22] => SURGERY START TIME [23] => SURGERY END TIME [24] => SVC UNIT [25] => FACILITY NAME [26] => BILLING NUMBER [27] => BILLING AREA NAME [28] => PROCEDURE MODIFIER1 [29] => PROCEDURE MODIFIER2 [30] => PROCEDURE MODIFIER3 [31] => PRIMARY DX [32] => SECONDARY DX [33] => THE END )
Array ( [CPT CODES] => CPT_Code [ASA CLASSFICATION] => MG_ASA_Class [FACILITY NAME] => Facility_Name [BILLING NUMBER] => Billing_Number [BILLING AREA NAME] => Billing_Area_Name [PROCEDURE MODIFIER1] => Procedure_Modifier1 [PROCEDURE MODIFIER2] => Procedure_Modifier2 [PRIMARY DX] => Primary_Dx [SECONDARY DX] => Secondary_Dx [INVOICE] => FIN )
The attribute is: FIN The index is: 6
You should test for a valid $attributeindex !
$attributeindex = array_search($index, $attributearray);
if ($attributeindex===FALSE) {
echo "Error : ".$index." not found <br />";
} else {
echo "<br>The attribute is: ".$value." The index is: ".$attributeindex."<br>";
}
If you get a not found Error you can be shure $index is not found in $attributearray .
Update :
This is very strange !
From your output we can clearly see.
$index == SECONDARY DX
and
$attributearray has a key [32]
[32] => SECONDARY DX
Only to test :
can you add to $attributearray at the end
[33] => 'END'
and see what happens.
Update 2 :
As i can see in the new output you got with
echo "<pre>";
print_r($attributenames);
echo "</pre>";
There is a empty line between [32] and [33].
There must be a invisible sign at the end of [32] => SECONDARY DX
I suspect a new line character.
Array
(
[0] => PATIENT MRN
[1] => PATIENT LAST NAME
....
[30] => PROCEDURE MODIFIER3
[31] => PRIMARY DX
[32] => SECONDARY DX
[33] => THE END
)
Try to remove that character and it should work .
TIP:
If you ever re experiencing similar behavior, you should check with :
for example:
echo bin2hex($attributenames[32]);
Output in windows look at the end :
5345434f4e444152592044580d0a
Where 0d is CR = Carriage return and 0a is LF = Line feed .
ASCII-Tabelle
Try using trim() on the value you are testing for. If there is white space you can't see at the end it won't match.
$attributeindex = trim( array_search($index, $attributearray) );
Related
i am writing a script to reach out to a website that downloads a csv into cache and then parses the data into an array.
$base_url = "http://www.collincad.org/ccad/propertysearch/download.php?situs_num=1707&situs_street=university&situs_street_suffix=&isd%5B%5D=any&city%5B%5D=any&prop_type%5B%5D=R&prop_type%5B%5D=P&prop_type%5B%5D=MH&active%5B%5D=1&year=2018";
$handle = fopen($base_url, "r");
$flag = true;
while(!feof($handle))
{
$text = fgetcsv($handle, 1024, ",");
if($flag) { $flag = false; continue; }
print $text[1]. " <br>";
}
mysql_close($connect);
When performing the query this way it has the first row and a row of other data and ignores the comma.
$base_url = "export5.csv";
$handle = fopen($base_url, "r");
$flag = true;
while(!feof($handle))
{
$text = fgetcsv($handle, 1024, ",");
if($flag) { $flag = false; continue; }
print $text[1]. " <br>";
}
mysql_close($connect);
but when i manually download the csv file it and read it from the local folder it works as expected... i would prefer not to make this a two step process... im thinking that reading direct from the site with php is the issue, just can figure out how to resolve it.
Thanks
First and foremost when using fopen with a web url, make sure your server is configured to allow it (http://php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen). Once that is out of the way you should be fine with your code.
The issue though is the CSV format itself.
Looking at the CSV return of that url, its delimiters are tabs, not commas. And I see no enclosures too. So you need to change your fgetcsv to:
$text = fgetcsv($handle, 1024, "\t", '');
And it should begin to return results like this (for each $text):
Array
(
[0] => 15071
[1] => 2018
[2] => P
[3] => Personal
[4] => P-9000-288-0243-1
[5] => N
[6] => ZZZZZZZ BPP # 1707 W UNIVERSITY DR
[7] =>
[8] =>
[9] =>
[10] =>
[11] =>
[12] => BPP AT 1707 W UNIVERSITY DR
[13] => KROGER #488
[14] => 1707
[15] => UNIVERSITY DR
[16] => MCKINNEY
[17] => 1707 W University Dr | McKinney, TX 75069
[18] => 844925
[19] => THE KROGER CO
[20] => CMC
[21] => MCKINNEY CITY
[22] => SMC
[23] => MCKINNEY ISD
[24] =>
[25] => Active
[26] => No
[27] =>
)
Also, the first line in the csv file is this:
Line 1:
Array
(
[0] => sep=
[1] =>
)
So you may want to skip the first TWO lines (the second line being the column headers).
Line 2: (column headers)
Array
(
[0] => Property ID
[1] => Year
[2] => Property Type Code
[3] => Property Type Description
[4] => Geographic ID
[5] => Abstract Or Subdivision Code
[6] => Abstract Or Subdivision Description
[7] => Block
[8] => Tract Or Lot
[9] => Mobile Home Park Code
[10] => Mobile Home Park Description
[11] => Mobile Home Park Space
[12] => Legal Description
[13] => Doing Business As
[14] => Street Number
[15] => Street Name
[16] => City
[17] => Complete Address
[18] => Owner ID
[19] => Owner Name
[20] => Taxing City Code
[21] => Taxing City Name
[22] => Taxing School District Code
[23] => Taxing School District Name
[24] => Market Value
[25] => Property Status
[26] => Certified Data
[27] =>
)
I have created a multi-dimensional array using fgetcsv from a CSV file.
Using both DOMDocument and SimpleXML I am trying to create a XML file of the CSV document.
The array and XML variables are being passed to a function within the same class file. The XML document is being created without any issues, but no value is passing from the array into the XML. It does work it I use a static value opposed to passing a value from the array, also if I print_r the array the structure and values are all correct.
I have tried 'htmlspecialcharacters' and 'encode_UTF8' before passing the value into the XML.
An example of the code is below, product is the multi-dimensional array.
public function array_to_xml($product, &$xml)
{
foreach($product as $row)
{
$element = $xml->createElement("Product");
$xml->appendChild($element);
$element = $xml->createElement("ID", ($row[38]));
$xml->appendChild($element);
}
}
The problem is obviously with the array but I can't find the answer. Any help would be gratefully appreciated.
The output currently looks like (with not value in the ID element). Once it is working Product will have about 20 child elements.
<?xml version="1.0"?>
<ProductList/>
<Product>
<ID/>
</Product>
</ProductList>
Example of $row when printed to screen:
Array ( [0] => [1] => [2] => 6/10/2016 [3] => [4] => [5] => 7.35 [6] => N [7] => N [8] => N [9] => 0 [10] => 0 [11] => 0 [12] => 0 [13] => 0 [14] => 80 [15] => 0 [16] => 80 [17] => 0 [18] => 80 [19] => N [20] => N [21] => N [22] => N [23] => 236.50 [24] => 0.00 [25] => 4.86 [26] => AFG Home Loans - Alpha [27] => 100% Offset Lo Doc Fixed [28] => 100% Offset Lo Doc 4 Year Fixed Owner Occupied [29] => 250.00 [30] => [31] => 7.35 [32] => 0.00 [33] => 4.9 [34] => N [35] => 325.00 [36] => 48 [37] => 4.52 [38] => 1-1MX78TF [39] => N [40] => [41] => [42] => N [43] => N [44] => [45] => Y [46] => 0.00 [47] => 10,000.00 [48] => 2,000,000.00 [49] => Y [50] => 30 [51] => [52] => [53] => Y [54] => 0.00 )
A couple things stand out. First, you have a syntax error on this line:
$element = $xml->createElement("ID", ($row[38])); (note the errant parentheses around $row[38]. The createElement method takes a String for its second parameter.
Second, you're not adding the ID to the product, but to the root XML. Fixing that, your code should look closer to this.
public function array_to_xml($product, &$xml)
{
foreach ($product as $row)
{
$product= $xml->createElement("Product");
$id = $xml->createElement("ID", $row[38]);
$product->appendChild($id);
$xml->appendChild($product);
}
}
If you need it as an attribute as #Barmar commented, you'd use the DOMElement->setAttribute() method, and it would look like:
public function array_to_xml($product, &$xml)
{
foreach ($product as $row)
{
$product= $xml->createElement("Product");
$product->setAttribute('ID', $row[38]);
$xml->appendChild($product);
}
}
SOLVED:
Had to put an initial value of ' ' for $rfield as hinted by KNaito BEFORE the loop (i.e. $rfield = ' ';).
Thank you!
ORIGINAL POST:
As a continuation of this problem, which was solved, a new problem arises where the output of the foreach loop is duplicated in one instance but not another:
Here is my loop:
foreach($fieldsarray as $field) {
${$field} = $globalrow[$field];
if(!empty($$field)) {$rfield.='<tr><td width="50%">'.${$field.'_label'}.': </td><td width="50%">'.${$field}.'</td></tr>';
}
}
$allrows=$rfield;
The $fieldsarray has too many elements to insert here, but it is like this:
$fieldsarray = array ('firstname','lastname','email');
$globalrow is a mysql query which fetches the data of the logged in user per mysql_fetch_assoc.
The expected HTML output will be a registration confirmation with a summary of the entered data shown on screen and also in the email confirmation which the user receives.
It is a table consisting of rows of the entered data. All data is saved in the DB.
The table rows are output correctly on the screen, e.g.:
First Name: John
Last Name : Smith
but for some weird reason in the email confirmation the output is duplicated:
First Name: John
Last Name : Smith
First Name: John
Last Name : Smith
In both cases I simply echo them with:
<?php echo $allrows ?>
As I said, I have read about the problems of duplicate output when using while and foreach with e.g. mysql_fetch_array - but as you can see this is not the case here, and why would this work fine on screen while in the email confirmation all elements are shown twice?
EDIT TO EXPLAIN TO USER COMMENtING BELOW:
I have a registration Form, where people register (insert personal data). When they fill out the form, they get to the summary page which shows their inserted data, like:
Prefix: Mr.
First Name: John
Last Name: Smith
After klicking "Submit" - the user is marked as "registered" and he receives an email confirmation.
The Email Confirmation itself is a simple HTML File with the addition of the PHP snippet which prints the rows with the User Data (exactly as shown on the Summary page).
Now, on the summary page, the output is OK, but in the email confirmation all data is DUPLICATED, and shown, eg. as:
Prefix: Mr.
First Name: John
Last Name: Smith
Prefix: Mr.
First Name: John
Last Name: Smith
So, why would this happen? Both Summary and Confirmation HTML is absolutely the same code.
EDIT (PRINT_R):
print_r($globalrow):
Array ( [regid] => 630 [eid] => 1 [guid] => xxxxxx-D898-CBE0-D018-xxxxxxx [regcomp] => 1 [regdate] => 2014-04-25 14:57:28 [prefix] => Mr.
[nametitle] => [firstname] => Xxxxx [lastname] => Xxxxxx [company] => XXXXXXX [department] => [jobtitle] => [street] => XXXXXXXX [zip] => 8217878979 [city] => XXXXX [country] => XXXXX [priv_street] => [priv_zip] => [priv_city] =>
[priv_country] => [phone] => XXXXXX [fax] => [mobile] => [email] => XXXXXXX [travel] => [terms] => [notes] => [accommodation] => [roompartner] => [arrivaldate] => [arrivaltype] => [arrivalairport] => [arrivalflightno] =>
[arrivaltransfer] => [departuredate] => [departuretype] => [departureairport] => [departureflightno] => [departuretransfer] =>
[dinner] => [dinnerpersons] => 0 [food] => [hotel] => [checkin] => [checkout] => [roomtype] => [special] => [hotelnotes] => [groupparticipanttype] => Companion [mainparticipantid] => 629 )
print_r($fieldsarray):
Array ( [0] => prefix [1] => nametitle [2] => firstname [3] => lastname [4] => company [5] => department [6] => jobtitle [7] => email
[8] => phone [9] => fax [10] => mobile [11] => street [12] => zip [13] => city [14] => country [15] => dinner [16] => dinnerpersons
[17] => food [18] => checkin [19] => checkout [20] => hotel [21] => roomtype [22] => roompartner [23] => special [24] => hotelnotes
[25] => accommodation [26] => arrivaldate [27] => departuredate [28] => notes [29] => terms )
This is what my array looks like :
Array (
[0] => SimpleXMLElement Object (
[key] => Array (
[0] => Track ID
[1] => Name
[2] => Artist
[3] => Album Artist
[4] => Composer
[5] => Album
[6] => Genre
[7] => Kind
[8] => Size
[9] => Total Time
[10] => Disc Number
[11] => Disc Count
[12] => Track Number
[13] => Year
[14] => Date Modified
[15] => Date Added
[16] => Bit Rate
[17] => Sample Rate
[18] => Play Count
[19] => Play Date
[20] => Play Date UTC
[21] => Artwork Count
[22] => Persistent ID
[23] => Track Type
[24] => Location
[25] => File Folder Count
[26] => Library Folder Count )
[integer] => Array (
[0] => 2056
[1] => 3732918
[2] => 230661
[3] => 1
[4] => 1
[5] => 1
[6] => 1993
[7] => 128
[8] => 44100
[9] => 3
[10] => 3439412487
[11] => 1
[12] => 5
[13] => 1 )
[string] => Array (
[0] => Eye of the Tiger
[1] => Survivor
[2] => Survivor
[3] => Frankie Sullivan/Jim Peterik
[4] => Greatest Hits
[5] => Rock
[6] => MPEG audio file
[7] => 772F0F53F195E705
[8] => File
[9] => file://localhost/Users/cameron/Music/iTunes/iTunes%20Media/Music/Survivor/Greatest%20Hits/01%20Eye%20of%20the%20Tiger.mp3 )
[date] => Array (
[0] => 2012-08-27T17:01:00Z
[1] => 2012-08-27T17:01:03Z
[2] => 2012-12-27T07:21:27Z ) )
that's 1 result, there is about 50 of them repeated.
I am trying to select the artist value in this case : Frankie Sullivan/Jim Peterik
please note: there is about 50 other results that come after this first one, so I would like to do a foreach to display all results.
any suggestions? I am stuck.this is the code I used to get these results:
$xml = simplexml_load_file('Library.xml');
$xmlx = $xml->dict->dict->dict->key;
$artist = $xmlx->xpath("//dict[key='Artist']");
echo "<pre>" . print_r($artist, true) . "</pre>";
It seems that you have an array of SimpleXMLElement,
so you can iterate over your array and use the SimpleXMLElement facilities.
Try:
foreach($yourArray as $simpleXmlElement)
{
// Retrieve the name
echo $simpleXmlElement->string[3];
}
Take a look at the documentation for more question: SimpleXMLElement
For your specific problem, assuming the key and string are synchronized, you can try:
// Loop on your array of SimpleXMLElement
foreach($yourArray as $simpleXmlElement)
{
// Initialize the position and found value
$position = 0;
$found = false;
// Loop on the sub array 'key' and search the 'Artist Album' position
foreach($simpleXmlElement->key as $index => $value)
{
if ($value == "Album Artist")
{
$found = true;
break;
}
// Not found, increment position
$position++;
}
// Retrieve the name if found the artist album key
if ($found)
echo $simpleXmlElement->string[$position];
}
As
[3] => Album Artist
will give the position 3
Then, when retrieving the string value, it will return Frankie Sullivan/Jim Peterik
I have a query that I'm running in php. The DB is SQL Server 2008.
The query in PHP is:
"SELECT * FROM applicants WHERE applicants.families_id = '{$family_array['id']}'";
Where the $family_array id is matched against the families_id. I get a single row as a result. I save that row to an array in PHP by using the mssql_fetch_array function. When I print this array I get the following:
Array
(
[0] => 26
[id] => 21
[1] => 21
[user_id] => 21
[2] => Kristi
[mother_fname] => Kristi
[3] => Lochala
[mother_lname] => Lochala
[4] => Nathan
[father_fname] => Nathan
[5] => Lochala
[father_lname] => Lochala
[6] =>
[app_emergency] =>
[7] =>
[upload_mother_passport] =>
[8] =>
[upload_mother_visa] =>
[9] =>
[upload_father_passport] =>
[10] => 0
[upload_father_visa] => 0
[11] => nathan-lochala
[user_added_username] => nathan-lochala
[12] => Mar 19 2013 01:00:37:660PM
[user_added_date] => Mar 19 2013 08:48:00:000AM
[13] => 192.168.88.15
[user_added_ip] => 192.168.88.15
[14] =>
[user_updated_username] =>
[15] =>
[user_updated_date] =>
[16] =>
[user_updated_ip] =>
[17] => 21
[18] => nathan-lochala
[username] => nathan-lochala
[19] => b9a234cb37ce2b75d77befecabfa650e39489e0b
[hash_password] => b9a234cb37ce2b75d77befecabfa650e39489e0b
[20] => Nathan
[fname] => Nathan
[21] => Lochala
[lname] => Lochala
[22] => 2
[num_child] => 2
[23] => Mar 19 2013 08:48:00:000AM
[24] => 192.168.88.15
[25] =>
[26] =>
[27] => nathan-lochala#shk.qsi.org
[email] => nathan-lochala#shk.qsi.org
[28] => parent
[access] => parent
)
If you notice, the index [0] does not match the corresponding key value [id]. 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?
EDIT:
Running mssql_fetch_assoc() gives me the following results:
Array
(
[id] => 21
[user_id] => 21
[mother_fname] => Kristi
You are not including all the pertinent information either in the posted SQL or in the table data/structure you've included. Your query is SELECT * FROM applicants WHERE applicants.families_id = ? yet the table structure you've posted does not contain a families_id column (nor is it named applicants). Nor does it contain much of the data in the posted array, e.g., hash_password, username, etc.
From this I deduce that you're actually doing a JOIN on a users table. What's most likely occurring is that the JOIN is including the id column from the users table which is overwriting the id in the main table (families/applicant, whatever it's called) once the array is built. user_id is already included in your main table so you should explicitly list the columns in your SQL statement, leaving out the users.id column.
You need to make it mssql_fetch_array($result, MSSQL_ASSOC) as MSSQL_BOTH is assumed.
I found the answer here:
http://php.net/manual/en/function.mssql-fetch-array.php