php - need the result of mysqli query as a json array from this phpscript -


this php script

$con = mysqli_connect(host,user,pass,db);  if($_server['request_method']=='get')  {  $qry_check="select * `tb_user`";  $stmt = $con->prepare($qry_check);  if ($stmt->execute()){       echo "success";  }}  else       echo "fail";  } ?> 

when run query on mysqli online server result have attached below need result json array when call json url, hanks in advance,enter image description here

enter image description here

try this

<?php      $con = mysqli_connect(host,user,pass,db);      if($_server['request_method']=='get')      {         $stmt = $con->prepare("select * tb_user");               if ($stmt->execute()) {                     $users = array();                     $user=$stmt->get_result();                      while($row = $user->fetch_assoc()){                         $users[]=$row;                      }                       $stmt->close();                                         echo json_encode($users);             } }  ?> 

or use code. add remaining columns in code full result

    <?php      $con = mysqli_connect(host,user,pass,db);      if($_server['request_method']=='get')      {         $stmt = $con->prepare("select user_id, category_id tb_user");               if ($stmt->execute()) {                     $users = array();                     $stmt->bind_result($user_id, $category_id);                       while ($stmt->fetch()) {                           $user["user_id"] = $user_id;                         $user["category_id"] = $category_id;                         $users[] = $user;                      }                       $stmt->close();                                         echo json_encode($users);             } }  ?> 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -