pass php mysql result to json array
by Ramshan[ Edit ] 2014-09-17 09:50:45
Sometimes you need to pass the mysql result into json array inorder to fetch the output in json defined format. In that scenario, use the following concept,
$getData=mysql_query("Your Mysql Query");
$jsonArr = array(); // declare array
while ($result = mysql_fetch_array($getData))
{
$fetchRow = array($result['fieldName']);
array_push($jsonArr,$fetchRow);
}
echo json_encode($jsonArr);
this code will give you result in the format,
[["val1"],["val2"],["val3"]]