8

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'];
}
codaddict
457k83 gold badges502 silver badges537 bronze badges
asked Aug 25, 2010 at 6:38
0

1 Answer 1

20
$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);
answered Aug 25, 2010 at 6:54
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.