1dxb Posted June 15, 2015 Share Posted June 15, 2015 I am very new to php. I have a simple website that loops through a mysql database and draws polygons for every row. It also assigns a custom attribute (name) to every polygon that the user can see when he clicks the polygon. When a user clicks the polygon, he should see the value of variable "bname". The code works perfectly when I assign bname to a coordinate from the DB: var bname = ('.$row[coord1].'); The code fails when I assign bname to another column that is a string: var bname = ('.$row[name].'); All data in the database is text format, I suspect that maybe I am using the wrong syntax to return a string value from the database? I need to assign bname to the name column in the database.. This is the full code: $findmap= 'SELECT * FROM build2'; if(!$result = $con->query($findmap)){ die('There was an error running the query [' . $con->error . ']'); } else { while ($row = $result->fetch_assoc()) { echo ' var polypath = [new google.maps.LatLng('.$row[coord1].'), new google.maps.LatLng('.$row[coord2].'), new google.maps.LatLng('.$row[coord3].'), new google.maps.LatLng('.$row[coord4].'), new google.maps.LatLng('.$row[coord5].'), new google.maps.LatLng('.$row[coord6].'), new google.maps.LatLng('.$row[coord1].') ]; var bname = ('.$row[name].'); var dxbmap = new google.maps.Polygon({ custom: bname, path:polypath, strokeColor:"#0000FF", strokeOpacity:0.8, strokeWeight:1, fillColor:"#0000FF", fillOpacity:0.1 }); dxbmap.setMap(map); google.maps.event.addListener(dxbmap, "click", function() { alert(this.custom); }); '; } } ?> Quote Link to comment Share on other sites More sharing options...
Solution Ch0cu3r Posted June 15, 2015 Solution Share Posted June 15, 2015 If $row[name'] contains a string then the value for the bname javascript variables needs to be wrapped in quotes not parenthesises var bname = \''.$row['name'].\''; // or var bname = "'.$row['name'].'"; Quote Link to comment Share on other sites More sharing options...
1dxb Posted June 15, 2015 Author Share Posted June 15, 2015 If $row[name'] contains a string then the value for the bname javascript variables needs to be wrapped in quotes not parenthesises var bname = \''.$row['name'].\''; // or var bname = "'.$row['name'].'"; Thanks for your help, that worked perfectly! Quote Link to comment 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.