I am new in PHP and just trying to encode mysql table's data into JSON format, and to get that i am using below script:
<?php
$objConnect = mysql_connect("localhost","root","root");
$objDB = mysql_select_db("mydatabase");
$strSQL = "SELECT * FROM member WHERE 1 ";
$objQuery = mysql_query($strSQL);
$intNumField = mysql_num_fields($objQuery);
$resultArray = array();
while($obResult = mysql_fetch_array($objQuery))
{
$arrCol = array();
for($i=0;$i<$intNumField;$i++)
{
$arrCol[mysql_field_name($objQuery,$i)] = $obResult[$i];
}
array_push($resultArray,$arrCol);
}
mysql_close($objConnect);
echo json_encode($resultArray);
?>
and getting result in below format:
[
{
"MemberID":"1",
"Name":"Weerachai"
},
{
"MemberID":"2",
"Name":"Win"
}
]
But what if i want to get response like this:
{
"members": [ // i want to add this array
{
"MemberID":"1",
"Name":"Weerachai"
},
{
"MemberID":"2",
"Name":"Win"
}
]
}