【问题标题】:php json_encode mysql resultphp json_encode mysql 结果
【发布时间】:2011-04-03 13:34:52
【问题描述】:

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

$sql = mysql_query("SELECT * FROM item_details WHERE posting_id='$item_number'"); 而($row = mysql_fetch_array($sql)) { $title = base64_decode($row['title']); $price = $row['price']; $seller_user = $row['user']; }

【问题讨论】:

    标签: php mysql json


    【解决方案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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-09-15
      • 2011-12-17
      • 2017-10-15
      • 1970-01-01
      • 2018-06-16
      • 1970-01-01
      • 2015-09-29
      相关资源
      最近更新 更多