Eoin Posted May 9, 2012 Share Posted May 9, 2012 Hi. I am having a problem with a php while loop.I am trying to draw a polygon using coordinates from a online data table called buildinglist.the loop is supposed to loop through each row drawing a polygon with each set of coordinates : <?php // Include file to Connnect to online database include_once "mysql_connect.php"; // Collects data from table $data = mysql_query("SELECT * FROM buildinglist") or die(mysql_error()); // puts the "buildinglist" info into the $info array // $info = mysql_fetch_array( $data ); ?> <!DOCTYPE HTML> <html> <head> <style type="text/css"> #theMap {background-image:url('MapImg.png'); } polygon:hover{fill:gold;} </style> <script type="text/javascript"> // This function is called when the lake is clicked. function buildingClick(<?php $id ?>) { // Display a fact. alert("<?php print $id; ?>"); } </script> </head> <body> <svg id="theMap" x="0" y="0" width="900" height="900"> <?php while($info = mysql_fetch_array( $data )){ //THE PROBLEM IS WITH THIS LINE// echo "<polygon fill="$info['fill_colour']" stroke="black" id="$info['id']" points="$info['coordinates']" />"; } ?> </svg> </body> </html> Can anybody help?it would be highly appreciated Eoin. Quote Link to comment https://forums.phpfreaks.com/topic/262300-parse-error-syntax-error-unexpected-t_variable-expecting-or-in-cxam/ Share on other sites More sharing options...
WatsonN Posted May 9, 2012 Share Posted May 9, 2012 echo "<polygon fill="$info['fill_colour']" stroke="black" id="$info['id']" points="$info['coordinates']" />"; I know you need to escape your quotes in the HTML echo "<polygon fill=".$info['fill_colour']." stroke=\"black\" id=".$info['id']." points=".$info['coordinates']." />"; Should work Quote Link to comment https://forums.phpfreaks.com/topic/262300-parse-error-syntax-error-unexpected-t_variable-expecting-or-in-cxam/#findComment-1344201 Share on other sites More sharing options...
Eoin Posted May 9, 2012 Author Share Posted May 9, 2012 That works perfectly.Thanks very much, hugely appreciated. Eoin. Quote Link to comment https://forums.phpfreaks.com/topic/262300-parse-error-syntax-error-unexpected-t_variable-expecting-or-in-cxam/#findComment-1344205 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.