Here is my code:
<?php
$sql = mysqli_query("SELECT thb_id FROM thumbnails LIMIT 10");
$result=mysqli_query($connection,$sql);
$count = mysqli_num_rows($sql);
if(isset($_GET['thb_id'])) {
$page = preg_replace('#[^0-9]#', '', $_GET['thb_id']);
} else {
$page = 1;
}
$lastPage = $count;
$total = 10;
if($page>1)
{
echo "<a href='project.php?project_id=".($page-1)."' class='button'>PREVIOUS</a>";
}
if($page!=$total)
{
echo "<a href='project.php?project_id=".($page+1)."' class='button'>NEXT</a>";
}
}
?>
My portfolio website is using PHP and MYSQL to call data from database, each project has an assigned ID(thb_id), and i am showing 10 projects ($total = 10;). The code above is for my previous and next button, and they are on my "project.php" page. However, it has an internal server error, and i don't know how to fix it.
The updated version:
<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
$sql = ("SELECT thb_id FROM thumbnails LIMIT 10");
$result=mysqli_query($connection,$sql);
$count = mysqli_num_rows($result);
if(isset($_GET['thb_id'])) {
$page = preg_replace('#[^0-9]#', '', $_GET['thb_id']);
} else {
$page = 1;
}
$lastPage = $count;
if($page < 1) {
$page = 1;
} else if($page > $lastPage) {
$page = 1;
}
?>
The new problem is: both prev and next buttons only take users to project 1(ID = 1).