Php Variable declaration error - MySQL -
i new php. have simple website loops through mysql database , draws polygons every row. assigns custom attribute (name) every polygon user can see when clicks polygon.
when user clicks polygon, should see value of variable "bname"
the code works when assign bname coordinate:
var bname = ('.$row[coord1].');
the code fails when assign bname column string:
var bname = ('.$row[name].');
all data in database text format, suspect maybe using wrong syntax return string value database? need assign bname name column in database..
this full code:
$findmap= 'select * build2'; if(!$result = $con->query($findmap)){ die('there error running 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); }); '; } } ?>
you need check console in browser js errors think encountering. try this
$findmap= 'select * build2'; if(!$result = $con->query($findmap)){ die('there error running 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); }); '; } } ?>
with current code console log think displaying like
uncaught referenceerror:
the parenthesis don't encapsulate string, trying those?
Comments
Post a Comment