-2
我試圖從數據庫中提取數據並將其轉換爲Json數據。無法從數據庫中提取數據並將其轉換爲Json數據
我有一個產品的ID,圖像,名稱和價格的表。我想將這些數據轉換成Json,然後將它們提取到我的網站。
<?php
//config is the file where i used to connect php to db
include_once('config.php');
// images is my table name
$sql= "SELECT * FROM `images` ";
$res= mysql_query($sql);
$result = array();
while ($row = mysql_fetch_array($res))
//image is stored as longbob, name as varchar and price as int
array_push($result, array('id'=> $row[0],
'image' = > $row[1],
'name'=> $row[2],
'price'=> $row[3]
))
echo json_encode(array());
?>
是什麼問題?將$ result放入json_encode中,就像echo json_encode($ result); –