首页 > 解决方案 > 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一样的函数?

有人能帮我吗?

标签: phprownext

解决方案


我认为您可以尝试将整个记录集存储在数组中,然后通过使用索引,您可以打印出下一行或上一行
例如

<?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'];
}
?>

推荐阅读