I have a page with the following code in which I am trying to paginate, at the moment it is only a test page.
It works fine except I can't get the value for the page to increase by 1 when you click the next button.
the code I have is as follows
It works fine except I can't get the value for the page to increase by 1 when you click the next button.
the code I have is as follows
Code:
<?php
$connection = mysql_connect("host","user","pass")
or die("Couldn't make connection.");
$db = mysql_select_db("marinas", $connection)
or die("Couldn't select database.");
$limit = 10;
$query_count = "SELECT * FROM marinas";
$result_count = mysql_query($query_count);
$totalrows = mysql_num_rows($result_count);
if (empty($page)){
$page = 1;
}
$limitvalue = ($page * $limit) - $limit;
$detailsquery = "SELECT * FROM marinas LIMIT $limitvalue, $limit";
$result = mysql_query($detailsquery, $connection) or die ("Error; " .mysql_error());
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php echo $page ?><br><br>
<?php
while ($row = mysql_fetch_array($result)) {
echo ($row["marinaname"]);
echo ("<br>");
}
?>
<br><br>
<?php
if ($page != 1) {
$pageprev = $page --;
echo ("<a href=\"test2.php?page=$pageprev\")Prev</a> ");
} else {
echo ("Prev ");
}
?>
<?php
if (($totalrows - ($limit * $page)) > 0) {
$pagenext = $page++;
echo "<a href=\"test2.php?page=$pagenext\">Next</a> ";
} else {
echo ("Next ");
}
?>
</body>
</html>