下面是我的php和geojson的样子。我想用逗号将它们分开,除了最后一个“while query”,因为它与传单一起工作。我试着在$data['geojson']后面回显一个逗号,但它在结尾也回显一个逗号,这使它无法工作。现在只要数据库中只有一行,它就可以工作。
geojson存储在geojson列中,每个geojson行都有自己的行
$sql = "SELECT * FROM `polygons` ORDER BY id";
$result = mysqli_query($dbcon, $sql);
$check = mysqli_num_rows($result);
if($check > 0){
echo '{"type":"FeatureCollection","features":[';
while($data= mysqli_fetch_assoc($result)){
echo $data["geojson"];
}
echo "]}";
GEOJSON:
{"type":"FeatureCollection","features":[{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[9.836037,54.92779],[9.79818,54.93067],[9.769213,54.924124],[9.745858,54.906048],[9.796566,54.879997],[9.860286,54.89273],[9.837761,54.925973],[9.836037,54.92779]]]}}
{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[9.855609,54.956418],[9.867858,54.923851],[9.971178,54.943613],[9.92426,54.969291],[9.855609,54.956418]]]}}]}