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 )
Related
I have a csv uploader i'm creating to push to an order api. Using phpSpreadsheets toArray method, i have an array like so:
Array
(
[0] => Array
(
[0] => product_sku
[1] => product_qty
[2] => shipping_name
[3] => shipping_address1
[4] => shipping_address2
[5] => shipping_city
[6] => shipping_county
[7] => shipping_postcode
[8] => shipping_type
[9] => customer_id
)
[1] => Array
(
[0] => test_sku_1
[1] => 3
[2] => Bruce Wayne
[3] => The Manor
[4] => Near Arkahm Asylumn
[5] => Gotham
[6] => Greater Gothan
[7] => B17MAN
[8] => 1
[9] => 14994333
)
[2] => Array
(
[0] => test_sku_2
[1] => 2
[2] => Bruce Wayne
[3] => The Manor
[4] => Near Arkahm Asylumn
[5] => Gotham
[6] => Greater Gothan
[7] => B17MAN
[8] => 1
[9] => 14994333
)
[3] => Array
(
[0] => test_sku_3
[1] => 7
[2] => Bruce Wayne
[3] => The Manor
[4] => Near Arkahm Asylumn
[5] => Gotham
[6] => Greater Gothan
[7] => L17MA2
[8] => 1
[9] => 14994333
)
)
Each order will be on a new line, however if a customer orders two different items, i need to group them together using their postcode. As such i was aiming to rearange into this format:
[orders] => Array(
Array(
[shipping_name] => "Bruce wayne",
[customer_id] => 14994333,
[address] => Array(
[shipping_address1] => "The Manor",
[shipping_address2] => "Near Arham Asylumn",
[shipping_city] => "Gotham",
[shipping_county] => "Greater Gotham",
[shipping_postcode] => "B17MAN",
)
[products] => Array(
Array(
[sku] => "test_sku_1",
[quantity] => 3
),
Array(
[sku] => "test_sku_2",
[quantity] => "2"
)
)
)
)
Once of the first problems i encountered was trying to match the postcodes. I managed to get a count using:
$getDuplicates = array_count_values(array_map(function($duplicates) {
return $duplicates[7]; //Where 7 is the postcode
}, $rows));
This worked in counting what i needed correctly. However from there i'm hitting a brick wall. If i'm counting the duplicates, i need it to also make a note of the rows it's already gone through so they aren't pushed incorrectly into the new array i want to make.
Pseudo it should be:
for each rows as row{
if row isn't set to be ignored{
for each count of this postcode{
array_push the product sku and qty
mark these rows as rows to be ignored
}
}
}
Can anyone help me with this?
So, long story short, i've been so caught up in this i completely missed the obvious. To solve this, i took the original array from phpspreadsheet and did an array_multisort:
foreach ($rows as $key => $row) {
$postcodes[$key] = $row[7]; //the postcode key
}
array_multisort($postcodes, SORT_DESC, $rows;
I then just worked my way through the array and if the postcode changed, i'd create a new array, otherwise i'd just push straight into the correct array for the products.
I feel really stupid i didn't think of this before. Thank you to #apokryfos for trying to help!
I got stuck with this error for quite a while and I can't figure out how to solve this problem. I double, even triple, checked data passed to transaction object and still can't find out why it keeps throwing me this " '' is less than 1 characters long " error message. I couldn't even find documentation for that error message on the internet.
Brief overview of current state of my code:
My transaction object creation is wrapped in try..catch statement (\Paymill\Services\PaymillException)
Client and Payment objects created correctly. I can see those two on my paymill control panel.
I'm passing shopping cart array to Transaction object as well
Item description is being derived using this sequence:trim(substr(html_entity_decode($item['description']), 0, 123)) . "..."
Payment is being made via credit card
First payment was successful second one fails
here's partial exception object output:
[__PHP_Incomplete_Class_Name] => Paymill\Services\PaymillException
[_errorMessage:Paymill\Services\PaymillException:private] => '' is less than 1 characters long
[_responseCode:Paymill\Services\PaymillException:private] =>
[_httpStatusCode:Paymill\Services\PaymillException:private] => 400
[_rawObject:Paymill\Services\PaymillException:private] =>
[message:protected] => '' is less than 1 characters long
[string:Exception:private] =>
[code:protected] => 400
...
[__PHP_Incomplete_Class_Name] => Paymill\Models\Request\Transaction
[_amount:Paymill\Models\Request\Transaction:private] => 6613
[_description:Paymill\Models\Request\Transaction:private] => Order ID: 111111-11111-1111
[_currency:Paymill\Models\Request\Transaction:private] => EUR
[_payment:Paymill\Models\Request\Transaction:private] => pay_1234566789
[_client:Paymill\Models\Request\Transaction:private] => client_123456
[_preauthorization:Paymill\Models\Request\Transaction:private] =>
[_token:Paymill\Models\Request\Transaction:private] => 123456
[_feeAmount:Paymill\Models\Request\Transaction:private] =>
[_feePayment:Paymill\Models\Request\Transaction:private] =>
[_feeCurrency:Paymill\Models\Request\Transaction:private] =>
[_source:Paymill\Models\Request\Transaction:private] =>
[_shippingAddress:Paymill\Models\Request\Transaction:private] => Array
(
[name] => Full name
[street_address] => full address
[street_address_addition] => N/A
[city] => full city
[state] => state as well
[postal_code] => 123456
[country] => CC
)
[_billingAddress:Paymill\Models\Request\Transaction:private] => Array
(
[name] => Full name
[street_address] => full address
[street_address_addition] => N/A
[city] => full city
[state] => state as well
[postal_code] => 123456
[country] => CC
[phone] => 123456
)
[_items:Paymill\Models\Request\Transaction:private] => Array
(
[0] => Array
(
[name] => full item name
[amount] => 123456
[description] => full description
[quantity] => 1
[item_number] => 123456-1
[url] => https://123123.html
)
...
[_shipping_amount:Paymill\Models\Request\Transaction:private] => 400
[_handling_amount:Paymill\Models\Request\Transaction:private] =>
[_mandateReference:Paymill\Models\Request\Transaction:private] =>
[_id:protected] =>
[_serviceResource:protected] => Transactions/
[_filter:protected] =>
)
[1] => create
)
)
This is how I initiate transaction
$transaction->setClient($this->getClient()->getId())
->setPayment($this->getPayment()->getId())
->setToken($this->getToken())
->setAmount($this->getBasket('total')*100)
->setBillingAddress($billing_address)
->setShippingAddress($shipping_address)
->setCurrency($this->getConfig('currency'))
->setItems($items)
->setDescription("Order ID: " . $this->getBasket('cart_order_id'))
->setShippingAmount($this->getBasket('shipping')['value']*100);
$this->d($this->getClient());
$r = $this->getRequest()->create($transaction);
Problem solved. One of the items was with empty description field. Strange that Exception did not include a field name which was causing problems.
I am using Chargify API (https://github.com/jforrest/Chargify-PHP-Client/), we have customers in thousands with monthly subscription, so they charged on their specific dates, i am using a cron which checks subscriptions on daily basis
Problem is we miss a subscription if it could not charged on date which suppose to be charged. Some time customer card could not charged due to no funds in their account or any reason happened with their cards which causes few days delay.
I want to know when a customer card charged in chargify so i can generate a new order that time, i have used above PHP Library but could not found a function which get me info.
Can any one help for this or any other solution to fix this ?
Thanks
Chargify has a feature specifically this called "Webhooks" (just like Paypal, Stripe, etc). Whenever there is activity on a customer's subscription (like a monthly renewal), Chargify will send a POST request directly to your server to alert you to it.
The specific documentation is here: https://docs.chargify.io/webhooks
No cron job necessary!
You can setup by webhook and get all the information immediately once customer charged and for that you need to setup webhook url on your server and then add it to chargify account, after login go to Settings -> Webhooks -> Add url for example:
http://www.domain.com/webhooks/
Create index.php file under "webhooks" directory and you will be getting an array from chargify like this:
Array
(
[id] => 29660474
[event] => renewal_success
[payload] => Array
(
[subscription] => Array
(
[activated_at] => 2014-12-12 06:11:51 -0500
[balance_in_cents] => 1900
[cancel_at_end_of_period] => false
[canceled_at] =>
[cancellation_message] =>
[created_at] => 2014-12-12 06:11:40 -0500
[current_period_ends_at] => 2015-02-12 06:11:40 -0500
[expires_at] =>
[id] => 7231335
[next_assessment_at] => 2015-02-12 06:11:40 -0500
[payment_collection_method] => automatic
[snap_day] =>
[state] => active
[trial_ended_at] =>
[trial_started_at] =>
[updated_at] => 2015-01-12 06:22:21 -0500
[current_period_started_at] => 2015-01-12 06:11:40 -0500
[previous_state] => active
[signup_payment_id] => 78110242
[signup_revenue] => 19.00
[delayed_cancel_at] =>
[coupon_code] =>
[total_revenue_in_cents] => 1900
[product_price_in_cents] => 1900
[product_version_number] => 6
[payment_type] => credit_card
[customer] => Array
(
[address] => xx xxxx place Success
[address_2] =>
[city] => Perth
[country] => AU
[created_at] => 2014-12-12 06:11:39 -0500
[email] => xxxxxxx#hotmail.com
[first_name] => Jay
[id] => 7093037
[last_name] => Gable
[organization] => Large
[phone] => xxxxxxxx
[portal_customer_created_at] => 2014-12-12 06:11:52 -0500
[portal_invite_last_accepted_at] =>
[portal_invite_last_sent_at] =>
[reference] => 548acd6a8ef3a
[state] => WA
[updated_at] => 2014-12-12 06:11:52 -0500
[verified] => false
[zip] => 6164
)
[product] => Array
(
[accounting_code] =>
[archived_at] =>
[created_at] => 2014-08-11 03:27:20 -0400
[description] => xxxx
[expiration_interval] =>
[expiration_interval_unit] => never
[handle] => monthly-subscription
[id] => 3493985
[initial_charge_in_cents] =>
[interval] => 1
[interval_unit] => month
[name] => 1 Pair Monthly
[price_in_cents] => 1900
[request_credit_card] => true
[require_credit_card] => true
[return_params] =>
[return_url] =>
[taxable] => false
[trial_interval] =>
[trial_interval_unit] => month
[trial_price_in_cents] =>
[update_return_url] =>
[updated_at] => 2014-12-11 17:09:41 -0500
[product_family] => Array
(
[accounting_code] =>
[description] => Standard Monthly Subscriptions
[handle] => monthly-subscription
[id] => 421701
[name] => Australia
)
[public_signup_pages] => Array
(
[id] => 100806
[url] => xx
)
)
[credit_card] => Array
(
[billing_address] => xxxxx Success
[billing_address_2] =>
[billing_city] => Perth
[billing_country] => AU
[billing_state] => WA
[billing_zip] => 6164
[card_type] => master
[current_vault] => braintree_blue
[customer_id] => 7093037
[customer_vault_token] =>
[expiration_month] => 2
[expiration_year] => 2015
[first_name] => XXXX
[id] => 4693476
[last_name] => Gable
[masked_card_number] => XXXX-XXXX-XXXX-xxxx
[vault_token] => xxxxxx
[payment_type] => credit_card
)
)
[site] => Array
(
[id] => xxxxx
[subdomain] => xxxxx
)
)
)
I hope this helps.
Easiest way would be to store last successful transaction date in DB and check frequently if a month has passed since last update with cron or mysql events scheduler, never used chargify but paypal api can communicate with your server and return status of transaction, which you can use on your site to update DB
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) );
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