I am fetching records from php & saving them in associative arrays. i want to create a json format like this
{
"contacts": [
{
"qid": "c201",
"question": "what is your name?,
},
{
"qid": "c202",
"question": "what is your age?
},
]}
I am using following code to get the data in php
<?
$response = array();
require("dbconfig.php");
$sql_get = 'SELECT qquesid,question FROM qhistory_data';
$retval = mysql_query( $sql_get, $conn );
if(!$retval )
{
$response["success"] = 0;
$response["message"]= mysql_error();
echo json_encode($response);
}
else
{
$num_rows=mysql_num_rows($retval);
if($num_rows>=0)
{
$i=0;
while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
{
$result_array[]= $row['question'];
$result_id[]=$row['qquesid'];
}
json_encode!?!?