خرید بک لینک

Vote count: 0

Here i am fetching data using php code.But i want the same code to be convert into json format.I am not getting the way to do it. I have tried it in this way.

my code

 while ($rows = mysql_fetch_array($filter)) {
        $result['name'] = $rows['name'];
        $result['id'] = $rows['id'];
    }

  $res = json_encode($result);
    print_r($res);

getting result

{"name":["sradha","nicky","demo","testing"],"id":["1","2","3","4"]}

Here i want it in this below json format

  [{id:1, name:'sradha'},
    {id:2, name:'nicky'},
    {id:3, name:'demo'},
    {id:3, name:'testing'}];

Please suggest me. Any suggestion will highly appreciate. Thank you in advance.

asked 1 min ago

1 Answer

Vote count: 0

Try this

$result = array();

while ($rows = mysql_fetch_array($filter)) {
    $result[] = $rows;
}

echo json_encode($result);

answered just now

- - , .

برچسب: نویسنده: استخدام کار تاريخ: چهارشنبه 5 اسفند 1394 ساعت: 11:37

صفحه بندی