Get ready for BLACK FRIDAY shopping starting in

Forums

PHP

This topic is locked

recordset paging problem

Posted 04 Jun 2006 15:48:18
1
has voted
04 Jun 2006 15:48:18 blair rose posted:
I am hoping that someone can help me with recordset paging. I am working with php and dreamweaver.
I have a database with 15 entries and have the repeat region set to show 5 records at a time.
The first 5 records display, I hit “next” and the second set show…..now the problem…..the
pages will not move to previous or next from this point. They just stay on the second set ex)
showing records 6 - 10 of 15 I am using php instead of asp….didn’t know if that mattered.

When I hit next the browser is displaying: localhost/pets/pets_view.php?pageNum_rspets=1&totalRows_rspets=16

When I hit the next button again the browser displays:

localhost/pets/pets_view.php?pageNum_rspets=1&totalRows_rspets=16?pageNum_rspets=2&totalRows_rspets=16

Here is the code that dream weaver generated:

hp require_once('Connections/pet_conn.php'); ?>
<?php
$currentPage = $_SERVER["PHP_SELF"];

$maxRows_rspets = 5;
$pageNum_rspets = 0;
if (isset($_GET['pageNum_rspets'])) {
$pageNum_rspets = $_GET['pageNum_rspets'];
}
$startRow_rspets = $pageNum_rspets * $maxRows_rspets;

mysql_select_db($database_pet_conn, $pet_conn);
$query_rspets = "SELECT * FROM pets";
$query_limit_rspets = sprintf("%s LIMIT %d, %d", $query_rspets, $startRow_rspets, $maxRows_rspets);
$rspets = mysql_query($query_limit_rspets, $pet_conn) or die(mysql_error());
$row_rspets = mysql_fetch_assoc($rspets);

if (isset($_GET['totalRows_rspets'])) {
$totalRows_rspets = $_GET['totalRows_rspets'];
} else {
$all_rspets = mysql_query($query_rspets);
$totalRows_rspets = mysql_num_rows($all_rspets);
}
$totalPages_rspets = ceil($totalRows_rspets/$maxRows_rspets)-1;

$queryString_rspets = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_rspets" == false &&
stristr($param, "totalRows_rspets" == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_rspets = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_rspets = sprintf("&totalRows_rspets=%d%s", $totalRows_rspets, $queryString_rspets);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Pet Database</title>
</head>

<body>
<p>
<a href="<?php printf("%s?pageNum_rspets=%d%s", $currentPage, max(0, $pageNum_rspets - 1), $queryString_rspets); ?>">Previous | </a><a href="<?php printf("%s?pageNum_rspets=%d%s", $currentPage, min($totalPages_rspets, $pageNum_rspets + 1), $queryString_rspets); ?>">Next</a><a href="<?php printf("%s?pageNum_rspets=%d%s", $currentPage, $totalPages_rspets, $queryString_rspets); ?>"> | Last</a> <a href="<?php printf("%s?pageNum_rspets=%d%s", $currentPage, max(0, $pageNum_rspets - 1), $queryString_rspets); ?>"></a></p>
<p> </p>
<table border="1">
<tr>
<td>id</td>
<td>name</td>
<td>breed</td>
<td>morf</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_rspets['id']; ?></td>
<td><?php echo $row_rspets['name']; ?></td>
<td><?php echo $row_rspets['breed']; ?></td>
<td><?php echo $row_rspets['morf']; ?></td>
</tr>
<?php } while ($row_rspets = mysql_fetch_assoc($rspets)); ?>
</table>
</body>
</html>
<?php
mysql_free_result($rspets);
?>

Please, please help...I have been stuck on this for over a week and I have reviewed the code 100x's but can not see what I am doing wrong..
thanks.

Replies

Replied 08 Aug 2007 23:17:02
08 Aug 2007 23:17:02 paul hampson replied:
Hi there.

I too have had the exact same problem, and it seems a lot of people have posted the same thing. I like yourself was passing variables from a search page to a detail page in dreamweaver using php/mysql. Everything worked fine, but when I tried to page onto the next page, everything comes up blank.

I managed to fix it! The answer is much simpler than what we were looking for.

It seems that the reason this problem occurs is because the form variables are not being passed onto preceeding detail pages when the user clicks on recordset navigation (ie. 'next' button etc...).

I found that by changing the form and recordset methods from POST to GET it solved the problem entirely.

On your 'Search Page' change the form method in the properties pannel from POST to GET. Then, open your results or detail page and double click on your recordsets. In the variables box, click 'Edit' on each variable and change the code to GET.

I hope this helps you. If you need any more help - let me know.

The meak may inherit the earth, but they better get the hell off the track!

Reply to this topic