Below is my code and it return me json array but i need to remove square bracket from response
JavaScript
x
$sql = "select user_loginId,user_password from wnl_user where user_loginId='student01' and user_password='123456' and user_status='active'";
//echo $sql;die;
$result = mysql_query($sql);
$num_rows = mysql_num_rows($result); //function to get number of rows from result
$posts = array();
if($num_rows != 0)
{
if(mysql_num_rows($result)) {
while($post = mysql_fetch_assoc($result)) {
$posts[] = array('status'=>'1','post'=>$post);
}
}
echo json_encode(array('posts'=>$posts));
}
else
{
echo json_encode(array('status'=>"0",'data'=>"No Data Found"));
}
And response is
JavaScript
{"posts":[{"status":"1","post":{"user_loginId":"student01","user_password":"123456"}}]}
i need to remove {“posts”:[ this from the starting square bracket and ]} also from the end.
Please help me out from this problem
Advertisement
Answer
Use, You can remove array('posts'
JavaScript
echo json_encode($posts);
instead of
JavaScript
echo json_encode(array('posts'=>$posts));