내가 JSON 배열 출력을 가지고 중복 된 JSON 배열을 받고 있지만, 문제가 무엇 0 번째 인덱스에 중복 json_array ... 나도 몰라 을 볼 수 아래는 중복 값 을 포함 필요 제안 및 왜...? 미리 감사드립니다PHP는
내 출력 :
[{"gallery_url":"fdkgvdjvb.img"}][{"gallery_url":"fdkgvdjvb.img"},{"gallery_url":"gdfgh.mp4"}]
필수 출력 :
[{"gallery_url":"fdkgvdjvb.img"},{"gallery_url":"gdfgh.mp4"}]
내 코드 :
<?php
$json = array();
$gallery=$_GET['gallery'];
$con=mysqli_connect("localhost","allluser","password4");
if($con)
{
//echo "connected";
}
$db_select = mysqli_select_db($con,'jumeirah_db');
if($db_select)
{
//echo "db selected";
}
$user_type=$_GET['user_type'];
$image=mysqli_query($con,"Select gallery_url from ju_gallery where user_type='$user_type'");
if ($image) {
while($r = mysqli_fetch_assoc($image)) {
$json[] = $r;
print json_encode($json);
}
}
mysqli_close($con);
?>
'while' 루프 내부에서'print json_encode ($ json);'문을 꺼내서 꺼내십시오. –
예, 작동합니다 ,,, 고마워요.하지만, 왜 이런 일이 생깁니 까. – arun
간단합니다. @arun. 각 행에 대해 JSON으로 인코딩 된 값을 인쇄하고 있습니다. ** 전체 배열 **의 JSON 표현 만 있으면됩니다. –