-1

My gmap page turns blank after inserting php code into the infowindow content.

google.maps.event.addListener(noi, 'mouseover', function() {
  var infowindow = new google.maps.InfoWindow({
    content: '<?php 
        if ($count==0){
        echo "No Open Tickets";
        }
    else{
        echo "<table>";
        foreach ($NOIcompliancearray as $SLA_Compliance=>$count) {
            $Npath = $Nimages[$SLA_Compliance];
            echo "<tr>";
            echo "<td><a href='city.php?city=Noida&compliance=".$SLA_Compliance."'><img src='IndiaImages/".$Npath."' title='".$SLA_Compliance."' ></td>";
            echo "<td>".$count."</td>";
            echo "</tr>";
            }
        echo "</table>";        
    }
  ?>'
    size: new google.maps.Size(100,100),
  });
google.maps.event.addListener(noi, 'mouseover', function() {
infowindow.open(map,noi);
setTimeout(function() { infowindow.close(map, noi) }, 5000);
});

If i replace php code with some static content it works fine. Also, when I tried opening the webpage source code, it gives me result which i wanted to see in the info window. I am not sure where I am making mistake.

output from the webpage source code: content:

'<table><tr><td><a href='city.php?city=Noida&compliance=A'><img src='IndiaImages/Circle_Red.gif' title='A' ></td><td>3</td></tr><tr><td><a href='city.php?city=Noida&compliance=C'><img src='IndiaImages/Circle_Yellow.gif' title='C' ></td><td>10</td></tr></table>Noida'

Kindly help me understand the mistake and to mitigate the problem.

TKAN
  • 38
  • 7
  • PHP runs serverside. The infowindow code runs in the client. Do a view source on your page. – geocodezip Apr 11 '15 at 21:53
  • under view source, it gives below output: content: '
    3
    10
    Noida'. Instead of php, should i write javascript to get the data displayed? Please suggest.
    – TKAN Apr 11 '15 at 22:04
  • @moskito-x : made the modification but system throwed " Parse error: syntax error, unexpected 'IndiaImages' (T_STRING), expecting ',' or ';' in C:\xampp\htdocs\map\gm4v2.php on line xx". the same code worked without any issue in css layer. – TKAN Apr 11 '15 at 22:20
  • @TrinathKanagala : my Bad I missread . I delete my comment. But what did you get with : `echo "";` – moskito-x Apr 11 '15 at 22:30
  • @moskito-x : I am soo sorry, you made some modification to the code. Didn't notice that. Now it displays the way it should. Thank you very much. Also, I would like to understand why you added slashes in between. Is it possible for you explain or guide me to proper channel so that I can understand better? – TKAN Apr 11 '15 at 22:48
  • @TrinathKanagala : I put it in my answer. – moskito-x Apr 11 '15 at 23:10

1 Answers1

0

Look at the function

google.maps.event.addListener(noi, 'mouseover', function() {
  var infowindow = new google.maps.InfoWindow({
    content: '...'
    size: new google.maps.Size(100,100),
  });

with php you get

google.maps.event.addListener(noi, 'mouseover', function() {
  var infowindow = new google.maps.InfoWindow({
    content: '<table>
            <tr>
            <td><a href='
   // 'city.php?city=......' is after content : string ending sign `'` will be ignored by function !
    size: new google.maps.Size(100,100),
  });

The first ' generated by php will interpreted as end of the string the rest will be in html source. you can see it but ignored by the function.

So don't use ' in that kind of code.

echo "<td><a href='city.php?city=Noida&compliance=".$SLA_Compliance."'>

escape the " sign instead

echo "<td><a href=\"city.php?city=Noida&ompliance=\"".$SLA_Compliance."\">"

escape " look here

moskito-x
  • 11,832
  • 5
  • 47
  • 60