php json_encode mysql 结果

标签 php mysql json

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

$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 结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3563389/

相关文章:

php - 未定义的属性,PDOException 错误

php - 如何在 XAMPP mac osx lion 中设置内存缓存

php - 创建富文本编辑器界面

MySql 根据其他字段值更新字段值

mysql - 多个表的 SQL 结构

json - 从 Json 中删除行

json - jq - 将父对象扁平化为子对象

PHP 无法发布到 MySQL 数据库

php - 使用 php/mysql 更新密码

json - TypeError : JSON. stringify(...).then 不是函数 - React JS