Page 1 of 1

PHP String issue with row[] SOLVED

Posted: Mon Jun 22, 2015 10:26 am
by PastorHank
I have trying to pass the patient's id to a javascript function. The ids are coming from a Select-sql which is providing the correct names. However when I select a record it turns out that instead of the complete string being sent to the Javascript any strings with dashes (if they have numbers are being subtracted) and if they contain blanks they are being ignored.

In my code I have

Code: Select all

<td width="100" align="center"><button type="button" onclick="listMedicallTreatments(<?php echo $row['patientl_id'];?>)">Get Treatments</button></td>
If the patient id is '985-121' it returns '784'.

I've tried

Code: Select all

<td width="100" align="center"><button type="button" onclick="listMedicallTreatments(<?php echo $row[\'patientl_id'\];?>)">Get Treatments</button></td>
Which gives me a
Parse error: syntax error, unexpected ''patient_id\'];?>)">Get Treatme' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING)
And I've tried

Code: Select all

<td width="100" align="center"><button type="button" onclick="listAnimalTreatments(<?php echo $row['\patient_id\'];?>)">
Which also generates a parse error

I've tried multiple variations and for the life of me I cannot figure out how to format that $row[patient_d] to send the correct string to the javascript function.

thank you

Re: PHP String issue with row[]

Posted: Mon Jun 22, 2015 12:59 pm
by Celauran
Have you tried wrapping it in quotes?

Code: Select all

<td width="100" align="center"><button type="button" onclick="listMedicallTreatments('<?php echo $row['patientl_id'];?>')">Get Treatments</button></td>

Re: PHP String issue with row[]

Posted: Mon Jun 22, 2015 2:15 pm
by PastorHank
Thank you, it was those outer quotes between the ( and the < that I had left off. Works like a charm now. I appreciate your help.