fork download
  1. <?php
  2.  
  3. // Controlamos los datos recibidos para paginar
  4. $page = isset($_GET['page']) ? (int) $_GET['page'] : 1;
  5. if ($page < 1) $page = 1;
  6. $records_by_page = isset($_GET['amount_show']) ? (int) $_GET['amount_show'] : 10;
  7. if ($records_by_page < 10) $records_by_page = 10;
  8.  
  9. $limit_from = ($page - 1) * $records_by_page;
  10.  
  11. // Inicializamos el arreglo de respuesta.
  12. $response = [
  13. 'records' => [],
  14. 'current_page' => $page,
  15. 'records_by_page' => $records_by_page,
  16. 'total_recors' => 0,
  17. ];
  18.  
  19.  
  20. $stmtT=$con->prepare("SELECT COUNT(*) AS total FROM users");
  21. $stmtT->execute();
  22. $stmtT->bind_result($total);
  23. while($stmtT->fetch()) {
  24. $response['total_recors'] = $total;
  25. }
  26.  
  27. $stmt = $con->prepare("SELECT id_user,
  28. id_customer,
  29. name,
  30. email,
  31. rol,
  32. register_date
  33. FROM users
  34. ORDER BY id_user DESC LIMIT $limit_from, $records_by_page");
  35. $stmt->execute();
  36. $stmt->store_result();
  37. $stmt->bind_result($id_user, $id_customer, $name, $email, $rol, $register_date);
  38.  
  39. while($stmt->fetch()) {
  40. $response['records'][] = [
  41. 'id_user' => $id_user,
  42. 'name' => $name,
  43. 'id_customer' => $id_customer,
  44. 'email' => $email,
  45. 'rol' => $rol,
  46. 'register_date' => $register_date
  47. ];
  48. }
  49. $stmt->close();
  50. header('Content-Type: application/json');
  51. echo json_encode($response);
Runtime error #stdin #stdout #stderr 0.02s 26016KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
PHP Notice:  Undefined variable: con in /home/a3twDZ/prog.php on line 20
PHP Fatal error:  Uncaught Error: Call to a member function prepare() on null in /home/a3twDZ/prog.php:20
Stack trace:
#0 {main}
  thrown in /home/a3twDZ/prog.php on line 20