Next row function in php

702
<?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))
{
?>

how to get next row in the database, I have tried with a function$res->movenext(), but get an error.

In Access the function is call docmd.GoTo, is there the same function I PHP?

Can someone help me?

337

Answer

Solution:

I think you can try to store the entire record set inside of an array and then by using an index you can print out the next row or the previous one
For example

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

People are also looking for solutions to the problem: php - Validation Radio Button Laravel 5.4

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.