2015-08-24 19 views
0

如何從數據庫中發送來自php的值。發送的值應該類似於「[.....]」。數據庫值使用PHP發送到Javascript

var locations = [ 
     ['Bondi Beach', -33.890542, 151.274856], 
     ['Coogee Beach', -33.923036, 151.259052], 
     ['Cronulla Beach', -34.028249, 151.157507], 
     ['Manly Beach', -33.80010128657071, 151.28747820854187], 
     ['Maroubra Beach', -33.950198, 151.259302] 
    ]; 

回答

0

你可以像這樣編碼它們並在javascript中使用它們。

$sth = mysqli_query("SELECT ..."); 
$rows = array(); 
while($r = mysqli_fetch_assoc($sth)) { 
    $rows[] = $r; 
} 
print json_encode($rows);