Dhaval2404

Php Json Test

Mar 9th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.71 KB | None | 0 0
  1. Example 1:
  2. <?php
  3. $result_attrs = array(
  4.  
  5.     array(
  6.             'id' => 1,
  7.             'name' => "name1"
  8.     ),
  9.  
  10.      array(
  11.            'id' => 2,
  12.             'name' => "name2"
  13.     )
  14.  
  15. );
  16.  
  17. $response = array (
  18.     'status'  => 0,
  19.     'message'=> "success",
  20.     'result' =>  $result_attrs
  21. );
  22.  
  23. echo json_encode($response);
  24.  
  25.  
  26. Example 2:
  27. $result_attrs = array();
  28.  
  29. $fetch = mysql_query("SELECT * FROM table");
  30.  
  31. while ($row = mysql_fetch_array($fetch, MYSQL_ASSOC)) {
  32.     $row_array['id'] = $row['id'];
  33.     $row_array['name'] = $row['name'];
  34.     array_push($result_attrs, $row_array);
  35. }
  36.  
  37. $response = array (
  38.     'status'  => 0,
  39.     'message'=> "success",
  40.     'result' =>  $result_attrs
  41. );
  42.  
  43. echo json_encode($response);
Add Comment
Please, Sign In to add comment