php - php中的下一行函数
问题描述
<?php
include "../conf/db-connect.php";
$res=mysqli_query($conn,"SELECT * FROM `main` WHERE `ribilleder` = 1 and
`rtbilleder` = 0");
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Page</title>
<link href="Rettelse_til_Billeder.css" rel="stylesheet">
<link href="index.css" rel="stylesheet">
</head>
<body>
<?php
if($_GET){
if(isset($_GET['nrettelse'])){
Nextrettelse();
}elseif(isset($_GET['frettelse'])){
Prevusrettelse();
}
}
function Prevusrettelse()
{
}
function Nextrettelse()
{
}
?>
<form >
<?php
while($row=mysqli_fetch_array($res))
{
?>
如何获取数据库中的下一行,我尝试了一个函数$res->movenext()
,但出现错误。
Access中的函数是调用docmd.GoTo,有没有和我PHP一样的函数?
有人能帮我吗?
解决方案
我认为您可以尝试将整个记录集存储在数组中,然后通过使用索引,您可以打印出下一行或上一行
例如
<?php
$i = 0;
$curr = 0;
$result = array();
$nRows = mysqli_num_rows($res);
//Populating the array
while($row=mysqli_fetch_array($res))
{
$result[i] = $row;
}
function Prevusrettelse()
{
if ($index > 0) $index--;
echo $result[$index]['id'];
}
function Nextrettelse()
{
if ($index < $nRows) $index++;
echo $result[$index]['id'];
}
?>
推荐阅读
- r - 如何将 case_when() 用于独占多个条件
- python - 无法在 Google Colab 中读取 csv 文件
- ios - Expo APNs 令牌 InvalidRegistration
- c# - 从 Outlook 获取电子邮件时,VSTO C# 中的 For 循环的性能问题
- api - openstack 如何通过计算 API 或连接 API 获取已删除的服务器列表
- c# - 使用 c# 在 azure bot 中结束对话反馈
- flutter - 使用颤振将sqlite db转换为pdf格式
- php - Laravel 5.8:试图获取非对象的属性“顺序”
- node.js - TS4090 节点定义冲突
- c# - 我无法控制的身份提供者的基于角色的 JWT 的最佳实践