이전 목록 다음
채택완료

json 변환 질문입니다.

json 변환 질문입니다. 

 

간단예제 공부중인데요

$sql = " select it_id from {$g5['g5_shop_item_table']}";

$result =  sql_query($sql); 

for ($i=0; $row=sql_fetch_array($result); $i++) {

$value = json_encode(array(

'id' => $row['it_id']

));   

echo $value;   

}  

 

페이지 확인해보면 결과값이

{"id":"1460083607"}{"id":"1460156140"}{"id":"1460156183"} 

이렇게 나옵니다.

 

제가 원하는 값은

[{"id":"1460083607"},{"id":"1460156140"},{"id":"1460156183"}]

이런 형태인데요


어떻게 해야 원하는 형태로 출력할수 있을까요?

감사합니다.

 

답변 2개 / 댓글 1개

채택된 답변
+20 포인트

$sql = " select it_id from {$g5['g5_shop_item_table']}";

$result =  sql_query($sql); 

for ($i=0; $row=sql_fetch_array($result); $i++) {

$value[] = array(

'id' => $row['it_id']

);   

}  

echo json_encode($value);

이렇게 해보세요.

Copy
$sql = " select it_id from {$g5['g5_shop_item_table']}";$result =  sql_query($sql); $value = array(); for ($i=0; $row=sql_fetch_array($result); $i++) {	$value[] = array(		'id' => $row['it_id']		);   }   echo json_encode($value);
 

답변에 대한 댓글 1개

우와 감사합니다 ㅎ 대박나실거에요!

답변을 작성하려면 로그인이 필요합니다.