我正在用PHP创建一个Web服务。 我想加载几个数据,比如说 10 记录。
因此,当它出现在移动应用中时,应显示第一个 10 记录,然后如果用户向下滚动,则应再次显示 10 记录。
<?php
$limit = 10; // limit of 10 records
$userQuery="SELECT * FROM (SELECT * FROM `agenda` WHERE agenda_event_id=$event_id
LIMIT $limit ) AS R1
INNER JOIN `bookmeeting` ON R1.agenda_id=bookmeeting.event_id";
$result=mysqli_query($conn,$userQuery);
$number=mysqli_num_rows($result);
while($row=mysqli_fetch_assoc($result)){
$getdata['data'][] = $row;
}
以上是我的代码。
我缺少哪里?
答案 0 :(得分:0)
请使用以下代码,您需要为每个请求设置$ page值。
//Need to set this variable when you send request to get next 10 records, default value would be 1
$page=1;
$offset = 10;
$limit = ($page - 1) * 10;
$userQuery="SELECT * FROM (SELECT * FROM `agenda` WHERE agenda_event_id= $event_id LIMIT $limit ) AS R1 INNER JOIN `bookmeeting` ON R1.agenda_id=bookmeeting.event_id";
if($page > 0)
$userQuery .= " limit $limit, $offset";
$result=mysqli_query($conn,$userQuery);
$number=mysqli_num_rows($result);
while($row=mysqli_fetch_assoc($result)){
$getdata['data'][] = $row;
}
//Need to set this variable when you send request to get next 10 records, default value would be 1
$page=1;
$offset = 10;
$limit = ($page - 1) * 10;
$userQuery="SELECT * FROM (SELECT * FROM `agenda` WHERE agenda_event_id= $event_id LIMIT $limit ) AS R1 INNER JOIN `bookmeeting` ON R1.agenda_id=bookmeeting.event_id";
if($page > 0)
$userQuery .= " limit $limit, $offset";
$result=mysqli_query($conn,$userQuery);
$number=mysqli_num_rows($result);
while($row=mysqli_fetch_assoc($result)){
$getdata['data'][] = $row;
}