Home > Back-end >  I dont understand how to list json from MYSQLI with params like ?currentPage=0&pageSize=18 [php]
I dont understand how to list json from MYSQLI with params like ?currentPage=0&pageSize=18 [php]

Time:12-28

Can someone please show me some examples or show me how, I already got the parms working but I dont know how i would do the api what im trying to do is make it get the data from my database with the currentpage and pagesize/limit I have got limit to work but I cant figure out how I would do current page

this is what ive got so far

<?php
require ($_SERVER['DOCUMENT_ROOT']."/core/config.php");
require ($_SERVER['DOCUMENT_ROOT']."/core/session.php");

if ($logged == false) {
    header('Location: /');
    exit;
}

    $limit = mysqli_real_escape_string($conn, $_GET['pageSize']);

if(intval($limit)) {
    $sqlSearch = "SELECT * FROM `users` ORDER BY `id` DESC LIMIT $limit";
    $result = $conn->query($sqlSearch);

    while ($userrows = $result->fetch_assoc()) {
        $username = $userrows['username'];

        $apiresp = array('success' => "true", 'username' => $username);
        echo json_encode($apiresp);
    }
}
?>

sorry if i explained this bad im kind of in a rush and have been trying for hours :(

CodePudding user response:

You probably want to use offset

SELECT * FROM `users` ORDER BY `id` DESC LIMIT $limit,". ($page -1)*$limit;
  • Related