2012-09-26 2 views
0

내가 구글에서 정보 창구글 맵 정보 창에 데이터베이스에서 데이터를 가져 오는 방법을

var infoWindow = new google.maps.InfoWindow({ 
    position: latlng, 
    content: 'Hello, world' 
    }); 

을 매핑하고 난 데이터베이스에서 주소를 검색 할 수있는 PHP 코드를 표시하려면이 코드가 있습니다.

<?php 
mysql_connect("localhost", "root", "root") or die (mysql_error()); 
mysql_select_db("theaterdb") or die(mysql_error()); 
$strSQL =("SELECT address FROM theaters WHERE theater_name='" . mysql_real_escape_string($_POST['course']) . "'"); 
$rs = mysql_query($strSQL); 
while($row = mysql_fetch_array($rs)) { 
echo "<b>Theater Address:</b><br>"; 
echo $row['address'] . "<br /><br />"; 
} 
mysql_close(); 
?> 

지금 난의이 작업을 수행하는 콘텐츠 field..how를 정보창을 데이터베이스에서 주소를 얻을 필요가? 아무도 도와 드릴 수 있습니다 .... 미리 감사드립니다.

답변

0

사용 mysql_fetch_assoc() 및 지정 $row 데이터베이스 값 : 보조 노트에 대한

<?php 
    $link = mysql_connect("localhost", "root", "root") or die (mysql_error()); 
    mysql_select_db("theaterdb", $link) or die(mysql_error()); 
    $strSQL = "SELECT address FROM theaters WHERE theater_name='" . mysql_real_escape_string($_POST['course']) . "'"; 
    $rs = mysql_query($strSQL); 
    $row = mysql_fetch_assoc($rs); 
    mysql_close(); 
?> 

<script> 
    var infoWindow = new google.maps.InfoWindow({ 
    position: latlng, 
    content: '<b>Theater Address:</b><br> <?php echo $row['address']; ?>' 
    }); 
</script> 

, 당신은 mysql_* 기능은 지원되지 않습니다으로 PDO에 코드를 이동하려고이 좋은 tutorial을 확인할 수 있습니다.

관련 문제