PHP json_encode mysql结果 [英] php json_encode mysql result
本文介绍了PHP json_encode mysql结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个简单的mysql_query
,我想在json中编码results(title= > $title, price => $price etc)
.
I have a simple mysql_query
and I would like to encode the results(title= > $title, price => $price etc)
in json .
$sql = mysql_query("SELECT * FROM item_details WHERE posting_id='$item_number'");
while($row = mysql_fetch_array($sql))
{
$title = base64_decode($row['title']);
$price = $row['price'];
$seller_user = $row['user'];
}
推荐答案
$sql = mysql_query("SELECT * FROM item_details WHERE posting_id='$item_number'");
$results = array();
while($row = mysql_fetch_array($sql))
{
$results[] = array(
'title' => base64_decode($row['title']),
'price' => $row['price'],
'seller_user' => $row['user']
);
}
$json = json_encode($results);
这篇关于PHP json_encode mysql结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文