0

i'm trying to get some json print. I have a simple format but i didn't figure it out.

But my result is like that. {"datas":{"title":"table"}}

    $sql = "SELECT * FROM mytable";
    $check = mysqli_fetch_array(mysqli_query($con,$sql));
    $array = array("table"=>$check["title"]);
    $result=json_encode(array('datas' => $array));
    echo($result);
    mysqli_close($con);

I need this is my format {"datas":[{"0":"table","title":"table"}]}

I guess i miss something.

2
  • 1
    use mysqli_fetch_assoc instead, need a mysqli version of stackoverflow.com/questions/11480129/… so it can be closed. Same applies anyway. Commented Nov 27, 2017 at 18:46
  • $array[] = $check; it works but i need to put some other data manually. Commented Nov 27, 2017 at 18:55

1 Answer 1

1

You should use this:

    $sql = "SELECT * FROM mytable";
    $check = mysqli_fetch_assoc(mysqli_query($con,$sql));
    $array = array("table"=>$check["title"]);
    $result=json_encode(array('datas' => $array));
    echo($result);
    mysqli_close($con);
Sign up to request clarification or add additional context in comments.

Comments