Buy Now
Sign in

Advance to next record

cruser , December 21 2021, 14:51
C
cruser 120
December 21 2021, 14:51 #397643
In my table view, I have a list of articles. These are sorted 1-100. When I click the link (gpage=viewArticle&id=1) to open to the article view I want to add a button or link at the bottom of the article page that will advance to gpage=viewArticle&id=2 when clicked. From that page, click to advance to gpage=viewArticle&id=3, and so on. How is this done? Anyone have an example to follow?
healyhatman 9
December 22 2021, 11:45 #397648
Read the database, getting the first ID higher than the ID you're on.
Web developer at SkySpider.com.au - I DO NOT work for ChronoEngine!
Donations: paypal.me/healyhatman
Professional Work: kamron@skyspider.com.au
Custom CF / CC Plugins and Extensions: skyspider.com.au/store
C
cruser 120
December 22 2021, 13:59 #397650
At the bottom of the article detail page (gpage=viewArticle&id=1) I have a button. From there I select the submit page to be (viewArticle). Is this where I begin with reading the DB and getting the first id higher than the id I'm on in the Where Conditions box? I guess this is the part that simply eludes me.
C
cruser 120
December 29 2021, 14:43 #397673
Anyone have any examples of how this can be done?
C
cruser 120
December 29 2021, 21:06 #397677
I have the code here that works, I just cannot figure out how to get it to run inside of CF7. Here's what I am using to read the DB outside of CF7 (for testing). I'd like to have the buttons at the bottom of my viewArticle that would advance to the next record based on id < or >. This code works, just can't figure out how to get it working inside CF7
<?php
require_once("config.php");
$id = $_GET['id'];
?>
<!DOCTYPE html>
<html>
<head>
<title>Previous and Next</title>

</head>
<body>
<?php
$result = mysqli_query($mysqli, "SELECT * FROM #_idtable WHERE id=$id");

if($row = mysqli_fetch_array($result))
{
$name = $row['name'];
$lot = $row['lot'];
}
?>

<h1> <?php echo $name;?></h1>
<p> <?php echo $lot;?></p>

<div class="group">
<?php
// Next button
$next = mysqli_query($mysqli, "SELECT * FROM #_idtable WHERE id>$id order by id ASC");
if($row = mysqli_fetch_array($next))
{

echo '<a href="show.php?id='.$row['id'].'"><button type="button">Next</button></a>';
}


// Previous button
$previous= mysqli_query($mysqli, "SELECT * FROM #_idtable WHERE id<$id order by id DESC");

if($row = mysqli_fetch_array($previous))
{

echo '<a href="show.php?id='.$row['id'].'"><button type="button">Previous</button></a>';
}


?>
</div>