php url and pagination
i have a problem in my code, when i click on page number the page is opening correctly but there are only 6 pages but there is no 7th page but when i am replacing the page number in the url to '7' the page is opening :(
why is this happening,,???
also i've created the auto links using url ecnode for fetched data of mysql but the the page which are not exist are also opening :(
for example , i have fetched a database row 'abc' so the link has created.
http://localhost/php/like.php?quote=abc
but when i am replacing this abc in the url with something else then the page is still opening :( it is not exist then why it is opening :( ?
<?php $name=$_POST['name']; ?>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="name">
<input type="submit" value="GO" name="submit">
</form>
<?php
include ('db.php');
if(isset($_POST['submit']))
{
mysql_query ("INSERT INTO example (name) VALUES('$name')") or die(mysql_error());
}
if (!isset($_GET['pagenum']) or !is_numeric($_GET['pagenum'])) {
$pagenum = 0;
}
else {
$pagenum = (int)$_GET['pagenum'];
}
$per_page=10;
$query = "SELECT * FROM example ORDER BY id DESC LIMIT $pagenum, $per_page";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
echo $row['name'] ." "." <a href= 'like.php?quote=" . urlencode( $row['name'] ) . "'>Click Here</a>";
echo "<br>";
}
$last = ceil ($total_rows/$per_page);
if ($pagenum > $last){
$pagenum=$last;
}
else if ($pagenum < 1 ){
$pagenum = 1;
}
for ($i=1; $i<=$last; $i++){
echo '<a href="'.$_SERVER['PHP_SELF'].'?pagenum='.($i).'"> '.$i.'</a>';
}
?>