尝试分页查询(第二次实验失败,分页显示成功,但数据库拿到的总数据还是10条,待解决)
This commit is contained in:
parent
f9fe11d9dc
commit
1e59ddb4d7
|
@ -68,8 +68,8 @@ int main(int argc, char const *argv[])
|
|||
char query_sql[128] = "";
|
||||
sprintf(
|
||||
query_sql,
|
||||
"select temperature, humidity , th_date_time from temp_hum_info;"); // 构建查询
|
||||
// "select temperature, humidity , th_date_time from temp_hum_info order by thid desc limit %d offset %d;", limit, (page - 1) * limit); // 构建查询
|
||||
// "select temperature, humidity , th_date_time from temp_hum_info;"); // 构建查询
|
||||
"select temperature, humidity , th_date_time from temp_hum_info ORDER BY thid DESC LIMIT %d OFFSET %d;", limit, (page - 1) * limit);
|
||||
|
||||
cJSON *result_array = cJSON_CreateArray();
|
||||
|
||||
|
|
|
@ -66,17 +66,20 @@
|
|||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<!-- 下一页,上一页按钮
|
||||
<!-- 下一页,上一页按钮 -->
|
||||
|
||||
<div class="page">
|
||||
<button onclick="prevPage()" id="prevPage">上一页</button>
|
||||
<button onclick="nextPage()" id="nextPage">下一页</button>
|
||||
</div> -->
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var currentPage = 1; // 当前页码
|
||||
|
||||
function loadBlackData() {
|
||||
var blackData;
|
||||
fetch("../cgi-bin/green_house_info_show.cgi")
|
||||
// fetch("../cgi-bin/green_house_info_show.cgi?page="+currentPage+"&limit=10")
|
||||
// fetch("../cgi-bin/green_house_info_show.cgi")
|
||||
fetch("../cgi-bin/green_house_info_show.cgi?page=" + currentPage + "&limit=10")
|
||||
.then(resp => resp.json())
|
||||
.then(data => {
|
||||
blackData = data;
|
||||
|
@ -101,16 +104,25 @@
|
|||
loadBlackData();
|
||||
}
|
||||
|
||||
// // HTML 页面中的按钮点击事件处理程序
|
||||
// function nextPage() {
|
||||
// currentPage++; // 增加当前页码
|
||||
// loadBlackData(); // 重新加载数据
|
||||
// }
|
||||
// HTML 页面中的按钮点击事件处理程序
|
||||
|
||||
// function prevPage() {
|
||||
// currentPage--; // 减少当前页码
|
||||
// loadBlackData(); // 重新加载数据
|
||||
// }
|
||||
function nextPage() {
|
||||
if (currentPage > 10) {
|
||||
alert("已经是最后一页了");
|
||||
return;
|
||||
}
|
||||
currentPage++; // 增加当前页码
|
||||
loadBlackData(); // 重新加载数据
|
||||
}
|
||||
|
||||
function prevPage() {
|
||||
if (currentPage < 1) {
|
||||
alert("已经是第一页了");
|
||||
return;
|
||||
}
|
||||
currentPage--; // 减少当前页码
|
||||
loadBlackData(); // 重新加载数据
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
|
|
Loading…
Reference in New Issue