Forum Moderators: coopster

Message Too Old, No Replies

parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecti

Using mysql php server side scripting

         

zilda

2:54 pm on Dec 23, 2004 (gmt 0)

10+ Year Member



I'm a novice/beginner php scripter. I'm an intermediate python developer and have written thousands of lines of python.

I tried adding code so that I could get to the columns of the returned rows. I took the example at www.php.net/manual/en/ref.mysql.php and tried modifying it so i could address specific columns from the results

the connection and all prior work. Its trying to address the columns that has problems.
the names of my columns are 'auction_no' and 'tracking_no'
this is what i did and it doesn't work:

while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "\t<tr>\n";
echo "\t\t<td>$line['auction_no']</td><td>$line['tracking_no']</td>\n";
echo "\t</tr>\n";
}

Should I post the whole script?

Thanks in advance

zilda

3:22 pm on Dec 23, 2004 (gmt 0)

10+ Year Member



fwiw, i installed jedit on my system but still don't see an error

zilda

3:30 pm on Dec 23, 2004 (gmt 0)

10+ Year Member



I figured it out.

Not sure why this works and the other didn't but I can move forward

here is how I fixed it

$auctNo = $line['auction_no'];
$trackNo = $line['tracking_no'];
echo "\t<tr>\n";
echo "\t\t<td>$auctNo</td><td>$trackNo</td>\n";
echo "\t</tr>\n";

rlkanter

4:46 pm on Dec 23, 2004 (gmt 0)

10+ Year Member



Double quotes will attempt to parse simple variables, for example $auctionNo or $trackNo, but not $line['auction_no'].

You could use this instead if you don't want to define temporary variables to handle it:

echo "\t\t<td>".$line['auction_no']."</td><td>".$line['tracking_no']."</td>\n";

coopster

6:00 pm on Dec 23, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, zilda.

This has to do with the method that PHP interprets arrays. It would actually be acceptable to not put quotation marks around the keys within the brackets in this case since the entire statement itself is a string (enclosed in double-quotes) and constants are not looked for within strings. However, that can get confusing, so I tend to use the braces syntax. Variable assignment or concatenation are also viable alternatives.

More information on how this works is found in the manual under Array do's and don'ts [php.net]. Read through the " More examples to demonstrate this fact:" section for details.

zilda

6:11 pm on Dec 23, 2004 (gmt 0)

10+ Year Member



Thanks for your help.

I'm going to look at the array dos and don'ts and also read up more on the strings.