Forums

PHP

This topic is locked

Recordset Problems

Posted 27 Jun 2005 20:00:09
1
has voted
27 Jun 2005 20:00:09 Chris Gates posted:
Hi Everyone,

I seem to be having problems with recordsets in dreamweaver mx 2004, MySQL, PHP. I am building a search engine for a model agency. I have built the search page (Basic dropdowns for haircolour etc) and results page. The problem I am having is with the results page.

the recordset populates and the first page of results is displayed correctly (records 1-10 of 272). Clicking next on the navigation bar should display records 11 - 20, the record count on the page says record 11 -20 of 272 but the results are not displayed.

It is almost as though the recordset although having 272 records in it is in fact empty, either that or the recordset paging isn't working correctly.

I have pasted all the code from the page below, any help would be wicked.

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

$maxRows_Results = 10;
$pageNum_Results = 0;
if (isset($_GET['pageNum_Results'])) {
$pageNum_Results = $_GET['pageNum_Results'];
}
$startRow_Results = $pageNum_Results * $maxRows_Results;

$colname_Results = "-1";
if (isset($_POST['sex'])) {
$colname_Results = (get_magic_quotes_gpc()) ? $_POST['sex'] : addslashes($_POST['sex']);
}
mysql_select_db($database_Modelling, $Modelling);
$query_Results = sprintf("SELECT * FROM artists WHERE Sex = '%s'", $colname_Results);
$query_limit_Results = sprintf("%s LIMIT %d, %d", $query_Results, $startRow_Results, $maxRows_Results);
$Results = mysql_query($query_limit_Results, $Modelling) or die(mysql_error());
$row_Results = mysql_fetch_assoc($Results);

if (isset($_GET['totalRows_Results'])) {
$totalRows_Results = $_GET['totalRows_Results'];
} else {
$all_Results = mysql_query($query_Results);
$totalRows_Results = mysql_num_rows($all_Results);
}
$totalPages_Results = ceil($totalRows_Results/$maxRows_Results)-1;

$queryString_Results = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_Results" == false &&
stristr($param, "totalRows_Results" == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_Results = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_Results = sprintf("&totalRows_Results=%d%s", $totalRows_Results, $queryString_Results);
?>
<!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>Search Results</title>
<style type="text/css">
<!--
.style3 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: small; }
.style4 {font-size: small}
-->
</style>
</head>
<body>
<p>
</p>



<table border="0">
<tr>
<td colspan="3"> Record <?php echo ($startRow_Results + 1) ?>to <?php echo min($startRow_Results + $maxRows_Results, $totalRows_Results) ?>of <?php echo $totalRows_Results ?> </td>
</tr>
<tr>
<td>id</td>
<td>FirstName</td>
<td>SurName</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_Results['id']; ?></td>
<td><?php echo $row_Results['FirstName']; ?></td>
<td><?php echo $row_Results['SurName']; ?></td>
</tr>
<?php } while ($row_Results = mysql_fetch_assoc($Results)); ?>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="3"> 
<table border="0" width="50%" align="center">
<tr>
<td width="23%" align="center"><?php if ($pageNum_Results > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_Results=%d%s", $currentPage, 0, $queryString_Results); ?>">First</a>
<?php } // Show if not first page ?>
</td>
<td width="31%" align="center"><?php if ($pageNum_Results > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_Results=%d%s", $currentPage, max(0, $pageNum_Results - 1), $queryString_Results); ?>">Previous</a>
<?php } // Show if not first page ?>
</td>
<td width="23%" align="center"><?php if ($pageNum_Results < $totalPages_Results) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_Results=%d%s", $currentPage, min($totalPages_Results, $pageNum_Results + 1), $queryString_Results); ?>">Next</a>
<?php } // Show if not last page ?>
</td>
<td width="23%" align="center"><?php if ($pageNum_Results < $totalPages_Results) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_Results=%d%s", $currentPage, $totalPages_Results, $queryString_Results); ?>">Last</a>
<?php } // Show if not last page ?>
</td>
</tr>
</table></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>

</table>
</body>
</html>
<?php
mysql_free_result($Results);
?>

PLEASE HELP ME

CHRIS

Reply to this topic