Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php json_encode mysql result

Tags:

json

php

mysql

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'];
}
like image 406
Michael Avatar asked Aug 25 '10 06:08

Michael


1 Answers

$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);
like image 91
reko_t Avatar answered Sep 18 '22 23:09

reko_t