Re: mysql_fetch_array and row referencing under 4.0.4pl1

From: Date: Tue, 13 Feb 2001 05:25:44 +0000
Subject: Re: mysql_fetch_array and row referencing under 4.0.4pl1
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-39350@lists.php.net to get a copy of this message
"Scott Brown" <scott-brown@home.com> wrote: > I grabbed an example of of php.net dealing with just arrays and it works ... > > Here's what I'm seeing - THIS WORKS: <snip> > while ( $row = mysql_fetch_array($rslt) ) > { > echo "<TR>\n"; > echo "<TD>$row[ID]</tD>"; </snip> > But put any one of these $row[...] with quotes around their fieldnames and I > get: > > Parse error: parse error, expecting T_STRING' or > T_VARIABLE' or > `T_NUM_STRING' in /home/testnexus/public_html/test.php on line 16 > > (when line 16 = > echo "<TD>$row["ID"]</tD>"; The double quotes enclose the contents of the echo statement, but PHP chokes because you have double quotes inside the echo statement. If the exact line above worked under PHP3.x I'm surprised. Solutions include: escaping the double quotes echo "<TD>$row[\"ID\"]</TD>"; using no quotes or single quotes: echo "<TD>$row['ID']</TD>"; echo "<TD>$row[ID]</TD>"; breaking apart the echo statement: echo "<TD>" . $row["ID"] . "</TD>"; I don't think there's any way around this. If you got it to work differently in PHP3 I'd like to know how. If for some reason you have a ton of code you have to change now, you can write a PHP script which uses regular expressions to find the double quotes to replace, write out the new files and cycle through all your files. It really wouldn't be that hard, but I still suspect that the double quotes would have been a problem in PHP3 too. -- Steve Werby COO 24-7 Computer Services, LLC Tel: 804.817.2470 http://www.247computing.com/

« previous php.general (#39350) next »