How to convert MYSQL query result into JSON?

Convert MYSQL query result into JSON

Team Leader Asked on February 11, 2017 in JSON.
Add Comment
1 Answer(s)

 

<?php

include "db.php";

$uid=$_REQUEST['uid'];

$data=array();

$sql=mysql_query("select * from tableName where user_id='$uid'");
while ($row=mysql_fetch_object($sql)){

$data[]=$row;

}

if(!empty($data)){

echo json_encode($data);

}else{

echo json_encode(false);

}

?>

 

Team Leader Answered on March 14, 2017.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.