PHP infinite loop to get MySQL data

Source: Internet
Author: User
This article mainly introduces the PHP infinite loop to obtain MySQL data method, the interested friend's reference, hoped to be helpful to everybody.

Specific as follows:

Public Function Get_data ($limit) {$sql = "select * FROM ((select Id,name from ' mytable ' limit {$limit},10) union ALL (select  Id,name from ' mytable ' limit 0,10)) as test limit 0,10 ";  return $this->query ($sql);}

The SQL statement above uses the union all method of MySQL to stitch together two sets and fetch the first 10 pieces of data.

Public Function GetCount () {//Gets the number of data bars     $sql = "SELECT count (ID) as T from ' mytable '";     return $this->query ($sql); }

The next step is to get the data in the controller and provide the data interface to Ajax.

Test database infinite loop fetch data public   function Getinfinitedata () {    //user clicks    $page = $_get[' click '];     Number of bars per display    $pagesize = 10; Gets the total number of bars    $total = $this->mydemo->get_count ();    $t = $total [0][0][' t ']; Calculates the starting position of each click    $limit = (($page-1) * $pagesize)% $t;    $data = $this->mydemo->get_data ($limit);    if (!empty ($data)) {      //convert to a two-dimensional array      $list = [];      foreach ($data as $key = + $v) {        $list [$key] = $data [$key][0];      }      $info [' msg '] = $list;      $info [' code '] = ' 001 ';    } else{      $info [' code '] = ' 002 ';      $info [' msg '] = ' no data ';    }    Echo Json_encode ($info, json_unescaped_unicode);d ie;  }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.