Hi,
I'm still really stuck!!!
I have managed the first part of paginating my code but however the previous and next buttons don't work. When I click on "next" the same results (first 5) are shown. I'm using php4 and MySQL.
Here's my code:
<?
define(MAX_DISPLAY, 5);
$link = mysql_connect("localhost", "yourdb", "yourpass"
or die("Could not connect : " . mysql_error());
mysql_select_db("genoa"
or die("Could not select database"
printf("<br>Row Start: %d Next Row: %d<br><br>\n", $page, $page+MAX_DISPLAY);
if(!$page) {
$page = 1;
printf("<a href='test.php?page=%s'>Next Page<br><br></a>", ($page + MAX_DISPLAY));
$query = "select * from example order by id asc limit ".MAX_DISPLAY."";
} else {
$query = "select * from example order by id asc limit ".($page - 1).",".MAX_DISPLAY."";
$prevpage = ($page - MAX_DISPLAY);
$page = ($page + MAX_DISPLAY);
printf("<a href='test.php?page=%s'>Next Page</a>", $page);
printf("<a href='test.php?page=%s'>Prev Page</a><br><br>", $prevpage);
}
$result = mysql_query($query)
or die("Could not complete query : " . mysql_error());
if(!$result) {
printf("No entries found.\n"
exit;
}
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
printf("[%d] - %s<br>\n", $row["id"], $row["name"]);
}
mysql_free_result($result);
mysql_close($link);
?>
Reality is built on a foundation of dreams.
I'm still really stuck!!!
I have managed the first part of paginating my code but however the previous and next buttons don't work. When I click on "next" the same results (first 5) are shown. I'm using php4 and MySQL.
Here's my code:
<?
define(MAX_DISPLAY, 5);
$link = mysql_connect("localhost", "yourdb", "yourpass"
or die("Could not connect : " . mysql_error());
mysql_select_db("genoa"
or die("Could not select database"
printf("<br>Row Start: %d Next Row: %d<br><br>\n", $page, $page+MAX_DISPLAY);
if(!$page) {
$page = 1;
printf("<a href='test.php?page=%s'>Next Page<br><br></a>", ($page + MAX_DISPLAY));
$query = "select * from example order by id asc limit ".MAX_DISPLAY."";
} else {
$query = "select * from example order by id asc limit ".($page - 1).",".MAX_DISPLAY."";
$prevpage = ($page - MAX_DISPLAY);
$page = ($page + MAX_DISPLAY);
printf("<a href='test.php?page=%s'>Next Page</a>", $page);
printf("<a href='test.php?page=%s'>Prev Page</a><br><br>", $prevpage);
}
$result = mysql_query($query)
or die("Could not complete query : " . mysql_error());
if(!$result) {
printf("No entries found.\n"
exit;
}
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
printf("[%d] - %s<br>\n", $row["id"], $row["name"]);
}
mysql_free_result($result);
mysql_close($link);
?>
Reality is built on a foundation of dreams.