Forum Moderators: coopster

Message Too Old, No Replies

Printing query results?

         

ramoneguru

10:31 pm on Aug 4, 2005 (gmt 0)

10+ Year Member



Code:
echo 'Applicant: $database["APPLICANT"] <br/>';
echo 'Loan Number: $database["LOAN NUMBER"] <br/>' ;

Output:
Applicant: $database["APPLICANT"]
Loan Number: $database["LOAN NUMBER"]

Everything connects fine and queries alright but, why won't this output correctly? I did a quick fix for it:

Code:
print "Applicant:" . $database['APPLICANT'] . "<br/>";
print "Loan Number:" . $database['LOAN NUMBER'] . "<br/>" ;

Output (what I wanted):
Applicant:Nick's School
Loan Number:006-03-ECA

I just don't understand why my initial try didn't do the job...Can someone please explain it to me?

--Nick

coopster

10:33 pm on Aug 4, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



It's the single quotation marks around the variable. PHP won't parse a string inside single quotation marks.

ramoneguru

10:44 pm on Aug 4, 2005 (gmt 0)

10+ Year Member



Maybe it's my setup then because this didn't work either:

print "Applicant: $database[APPLICANT] <br/>";
print "Loan Number: $database[LOAN NUMBER] <br/>";

Grrr....
--Nick

jatar_k

10:48 pm on Aug 4, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you can't use arrays within double quotes either, it won't work

the proper syntax would be the one you used

print "Applicant:" . $database['APPLICANT'] . "<br/>";
print "Loan Number:" . $database['LOAN NUMBER'] . "<br/>" ;

or

print "Applicant: {$database[APPLICANT]} <br/>";
print "Loan Number: {$database[LOAN NUMBER]} <br/>";

coopster

11:18 pm on Aug 4, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I should have also given you some links ...

Here is the quote/double quote differences explained in PHP Strings [php.net]

And here is the Array [php.net] syntax as suggested by jk.

ramoneguru

9:01 pm on Aug 11, 2005 (gmt 0)

10+ Year Member



Sorry about the late reply. Thanks for the help coopster and jatar_k, I get it now.
--Nick