Pagination Problem

vasquezjp56

New Member
Messages
2
Reaction score
0
Points
0
Problem:I want to disable the next button if there's no more data.. In phpacademy tutorials if there's no more data then I click next button a message appear saying "Ooopps, This doesn\'t exist!". How can be possible to disable the next button if there's no more data?
<?php
//max displayed per page
$per_page = 4;

//get start variable
$start = isset($_GET['start']) ? $_GET['start'] : 0;

if (!$start)
$start = 0;

if(isset($_GET['id'])):
$obj->get_content($_GET['id'], 0, 1, true);
else:
$obj->get_content(NULL, $start, $per_page);
endif;
?>
<?php

//count records
$record_count = mysql_num_rows(mysql_query("SELECT * FROM data"));

//count the max pages
$max_pages = $record_count / $per_page; //may come out as decimal

//setup prev and next variables
$prev = $start - $per_page;
$next = $start + $per_page;


if(!isset($_GET['id'])) {

//show page numbers


//show next button

echo "<div id='pagination'><a href='index.php?start=$next'>Next</a>";

//set variable for first page
$i=1;

for ($x=0;$x<$record_count;$x=$x+$per_page)
{
if ($start!=$x)
echo " <a href='index.php?start=$x'>$i</a> ";
else
echo " <a href='index.php?start=$x'><b>$i</b></a>";
$i++;

}
//show prev button
if (!($start<=0))
echo "<a href='index.php?start=$prev'>Prev</a>";
}
?><?php
function get_content($id = '', $start, $per_page, $one = false) {

if($id != ""):
$id = mysql_real_escape_string($id);
$sql = "SELECT * FROM data WHERE id = '$id'";
$return = '<a href="index.php"><button>Go back to content</button></a>';
else:
$sql = "SELECT * FROM data ORDER BY id DESC LIMIT $start, $per_page ";
endif;

$res = mysql_query($sql) or die(mysql_error());

if(mysql_num_rows($res) != 0):
while($row = mysql_fetch_assoc($res)) {
if($one) {
echo '<div class=""><h1>'.$row['title'].'</h1></div>';

} else {
echo '<div class=""><h1><a href="index.php?id='.$row['id'].'">'.$row['title'].'</a></h1></div>';
}
}
else:
echo '<p>Ooopps, This doesn\'t exist!</p>';
endif;
echo @$return;

} ?>
 
Top