一尘不染

PHP json_encode mysql结果

json

我有一个简单的mysql_query,我想results(title= > $title, price => $price etc)在json中编码。

$ sql = mysql_query(“ SELECT * FROM item_details WHERE posts_id ='$ item_number'”);

 while($ row = mysql_fetch_array($ sql))
{
   $ title = base64_decode($ row ['title']);
   $ price = $ row ['price'];
   $ seller_user = $ row ['user'];
}

阅读 297

收藏
2020-07-27

共1个答案

一尘不染

$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);
2020-07-27