Can anyone help me out, I'm currently struggling with a paged recordset. I am getting the correct number of totalrows returned, but when I actually go to page through the records I find there is a duplication of records.
I've sat here all day trying to work out the problem but can't see the problem, maybe a fresh set of eyes will be able to work it out.
Here is a portion of the code, I can post all the code if neccesarry but I think this should suffice:
mysql_select_db($database_conVillas, $conVillas);
// Maximum SQL Count
$test = mysql_query($sql) or die(mysql_error());
$totalRows = mysql_num_rows($test);
while($row = mysql_fetch_assoc($test)){
$rows[$row[ID]] = $row; // Any duplication _should_ overwrite the previous instance
}
// SQL LIMIT
if (isset($HTTP_GET_VARS['pageNum'])) {
$pageNum = $HTTP_GET_VARS['pageNum'];
}
$startRow = $pageNum * $maxRows;
$result_limit = sprintf("%s LIMIT %d, %d", $sql, $startRow, $maxRows);
$result = mysql_query($result_limit, $conVillas) or die(mysql_error());
//$totalPages = ceil($totalRows/$maxRows)-1;
if (isset($HTTP_GET_VARS['totalRows'])) {
$totalRows = $HTTP_GET_VARS['totalRows'];
} else {
$test = mysql_query($sql) or die(mysql_error());
$totalRows = mysql_num_rows($test);
while($row = mysql_fetch_assoc($test)){
$rows[$row[ID]] = $row; // Any duplication _should_ overwrite the previous instance
}
}
$totalRows = count($rows);
$totalPages = ceil($totalRows/$maxRows)-1;
?>
Showing
record <?php echo ($startRow + 1) ?> to <?php echo min($startRow + $maxRows, $totalRows) ?>
of <?php echo $totalRows ?>
<?php
if ($totalRows == 0){
echo 'Sorry your search did not return any results. Please return to the search page <a href=search.php>here</a>';
} else {
while($row = mysql_fetch_assoc($result)){
echo "<p>";
echo $row[ID]. "<br>";
echo $row[Name]. "<br>";
echo $row[Short_Description];
}
}