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; }