-3
我试图在beetwen中添加一个空格我的php,我需要在输出后添加一个空格并在最后一次输出中删除逗号。这里是我的代码在php输出之间添加空格
<div id="demo-1" data-zs-src='[
<?php
$sql = "SELECT * FROM slider ORDER BY no_urut ASC";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
while ($data = mysqli_fetch_assoc($result)) {
echo "\"images/slideshow/".$data['img']."\",";
}
}
?>
]' data-zs-overlay="dots"></div>
,当我运行的代码,它是这样的
data-zs-src="["images/slideshow/img1.jpg","images/slideshow/img2.jpg","images/slideshow/img3.jpg",]"
,但我想要的代码是这样的
data-zs-src="["images/slideshow/img1.jpg", "images/slideshow/img2.jpg", "images/slideshow/img3.jpg"]"
除了这个,你可能会想使用单引号与您的阵列。否则,'data-zs-src'只会计算为''[“'(数组的其余部分抛出语法错误)。 –
您应该使用[json_encode()](http://php.net/manual/en/function.json-encode.php)来代替它,为什么它内联?另外如果你只使用'img'列为什么要返回所有'*'? –