PHP Newbie problem - Parse error: syntax error, unexpected '=', expecting T_VARIABLE or '$'
New to php, doing a tutorial to use php on the server side to connect to flex. I have typed in the code for the video tutorial below but i can't seem to get it to work for me. The plan is put longitude and latitude data from the SQL database, format it as xml and pull it into flex The php code is as follows
<?PHP
mysql_connect("localhost", "root", "");
mysql_select_db("demo");
$result = mysql_query("select * from maps");
echo "<?xml version=\"1.0\" ?><map>";
while($row = mysql_fetch_assoc($result))
{
echo "<loc><lat>" . $row["lat"] . "</lat>";
echo "<lon>" . $row["lon"] . "</lon>";
echo "<name>" . $row["name"] . "</name></loc>";
}
echo "</map>";
?>
And the error I receive is:
Parse error: syntax error, unexpected '=', expecting T_VARIABLE or '$' in C:\wamp\www\Afghan_Mapping-debug\map.php on line 10
I have checked and double checked for open brackets or quotes but can't see any. I'm using WAMP.
开发者_如何学JAVAIf anyone can make any sense of it I'd appreciate it,
Thanks
while(.$row = mysql_fetch_assoc($result))
should be
while($row = mysql_fetch_assoc($result))
(without the dot)
I can't tell if it's the posts formatting, but could it be the way it's interpreting the line before it: echo "";
Typically, the line number the error is associated with is often the line/statement after where the real error is, because when it get's line 10, it realizes somethings not right based on what it just interpreted from the previous line. Funny, but that's how I've noticed it goes.
try using a foreach instead of while:
$row = mysql_fetch_assoc($result);
foreach($row as $r)
{
echo "<loc><lat>" . $r["lat"] . "</lat>";
echo "<lon>" . $r["lon"] . "</lon>";
echo "<name>" . $r["name"] . "</name></loc>";
}
Strange, I'm able to get this code to parse without any issue.
精彩评论