PHP String issue with row[] SOLVED

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
PastorHank
Forum Contributor
Posts: 117
Joined: Sat Jun 03, 2006 7:58 am
Location: Texas Hill Country

PHP String issue with row[] SOLVED

Post 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
Last edited by PastorHank on Mon Jun 22, 2015 2:16 pm, edited 1 time in total.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP String issue with row[]

Post 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>
PastorHank
Forum Contributor
Posts: 117
Joined: Sat Jun 03, 2006 7:58 am
Location: Texas Hill Country

Re: PHP String issue with row[]

Post 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.
Post Reply