How to do Pagination for JSON data in PHP?

前端 未结 4 936
我寻月下人不归
我寻月下人不归 2021-01-01 05:13

I don\'t have direct access to database from PHP. if it was so, I could have done pagination simply. Here I send a GET request to a PHP web service, and the result from the

4条回答
  •  温柔的废话
    2021-01-01 05:26

    You have several options available, the 'best' two I would suggest are the following:

    PHP solution:

    use sessions, (aka put session_start(); before every php file that will need access to session variables, also add a script to cause the session to timeout)

    Store the DB output to a session variable, if the session variable is not set.

    if (!isset($_SESSION['tabledata'])) {
        $json_data_fromdb= httpGet($ur3l."fromtable?u=".$var1."&ip=".$var2);
        $array = json_decode($json_data_fromdb, true);
        $_SESSION['count']=count($array['qqq']);
        $_SESSION['tabledata'] = $array['qqq'];
    }
    

    Then, you can simply paginate through the data, by sending a request for a certain range of values.

    Alternatively, you can use a javascript solution like Datatables And either load all the information and let datatables filter it, or let datatables communicate with the other PHP server directly.

提交回复
热议问题