Whilst playing around with the display of the records on one of my pages, I have come up with a drop down list with four options, 1 is static and the other three are generated by from a database.
There are 555 records in the table and only 15 are shown on each page, when I select the option from the drop down list, the page only shows the details requested, but when you move to the next page, it reverts to all records.
The form code for the dropdown menu is
<form id="insertForm" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get" name="form1">
<table border="0" cellspacing="0" cellpadding="0" id="insertTable">
<tr>
<th valign="middle">Select Location</th>
<td>
<select name="build" id="build">
<option value="" <?php if (isset($_GET['build']) && $_GET['build'] == "") { ?>
selected="selected"
<?php } ?>>All Build Locations</option>
<?php
do {
?>
<option value="<?php echo $row_rsLocations['locID']?>"
<?php if (isset($_GET['build']) && $_GET['build'] == $row_rsLocations['locID']) { ?>
selected="selected"
<?php } ?> ><?php echo $row_rsLocations['locName']?></option>
<?php
} while ($row_rsLocations = mysql_fetch_assoc($rsLocations));
$rows = mysql_num_rows($rsLocations);
if($rows > 0) {
mysql_data_seek($rsLocations, 0);
$row_rsLocations = mysql_fetch_assoc($rsLocations);
}
?>
</select>
</td>
<td><input type="submit" id="button" value="Submit"></td>
</tr>
</table>
</form>
This is the coding for displaying the records and paging.
<table border="0" cellpadding="0" cellspacing="0" id="repeatTable">
<tr>
<th scope="col">Works No.</th>
<th scope="col">Built At</th>
<th scope="col">Original No.</th>
<th scope="col">Built For</th>
<th scope="col">Date Intro</th>
<th scope="col">Last Number</th>
<th scope="col">Disposal</th>
</tr>
<?php do { ?>
<tr>
<td class="<?php echo $row_rsBuildlist['Disposal']; ?>"><?php echo $row_rsBuildlist['WorksNumber']; ?></td>
<td class="<?php echo $row_rsBuildlist['Disposal']; ?>"><?php echo $row_rsBuildlist['BuildID']; ?></td>
<td class="<?php echo $row_rsBuildlist['Disposal']; ?>"><?php echo $row_rsBuildlist['OrigNumber']; ?></td>
<td class="<?php echo $row_rsBuildlist['Disposal']; ?>"><?php echo $row_rsBuildlist['Company']; ?></td>
<td class="<?php echo $row_rsBuildlist['Disposal']; ?>"><?php echo date('m/Y',strtotime($row_rsBuildlist['ServiceDate'])); ?></td>
<td class="<?php echo $row_rsBuildlist['Disposal']; ?>"><?php echo $row_rsBuildlist['LastNumber']; ?></td>
<td class="<?php echo $row_rsBuildlist['Disposal']; ?>"><?php echo $row_rsBuildlist['Disposal']; ?></td>
</tr>
<?php } while ($row_rsBuildlist = mysql_fetch_assoc($rsBuildlist)); ?>
</table><br>
<?php if ($totalRows_rsBuildlist > $maxRows_rsBuildlist) { ?>
<p id="paging">
<?php if ($pageNum_rsBuildlist > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_rsBuildlist=%d%s", $currentPage, 0, $queryString_rsBuildlist); ?>"><<</a>
<?php } // Show if not first page ?>
<?php if ($pageNum_rsBuildlist == 0) { // Show if first page ?>
<span class="inactive"><<</span>
<?php } // Show if first page ?>
<?php if ($pageNum_rsBuildlist > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_rsBuildlist=%d%s", $currentPage, max(0, $pageNum_rsBuildlist - 1), $queryString_rsBuildlist); ?>"><</a>
<?php } // Show if not first page ?>
<?php if ($pageNum_rsBuildlist == 0) { // Show if first page ?>
<span class="inactive"><</span>
<?php } // Show if first page ?>
<?php if ($pageNum_rsBuildlist < $totalPages_rsBuildlist) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_rsBuildlist=%d%s", $currentPage, min($totalPages_rsBuildlist, $pageNum_rsBuildlist + 1), $queryString_rsBuildlist); ?>">></a>
<?php } // Show if not last page ?>
<?php if ($pageNum_rsBuildlist >= $totalPages_rsBuildlist) { // Show if last page ?>
<span class="inactive">></span>
<?php } // Show if last page ?>
<?php if ($pageNum_rsBuildlist < $totalPages_rsBuildlist) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_rsBuildlist=%d%s", $currentPage, $totalPages_rsBuildlist, $queryString_rsBuildlist); ?>">>></a>
<?php } // Show if not last page ?>
<?php if ($pageNum_rsBuildlist >= $totalPages_rsBuildlist) { // Show if last page ?>
<span class="inactive">>></span>
<?php } // Show if last page ?>
<?php } ?>
<?php if ($totalRows_rsBuildlist > 0) { // Show if recordset not empty ?>
Records <?php echo ($startRow_rsBuildlist + 1) ?> to <?php echo min($startRow_rsBuildlist + $maxRows_rsBuildlist, $totalRows_rsBuildlist) ?> of <?php echo $totalRows_rsBuildlist ?>
<?php } // Show if recordset not empty ?></p>
My coding for the query is
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$maxRows_rsBuildlist = 15;
$pageNum_rsBuildlist = 0;
if (isset($_GET['pageNum_rsBuildlist'])) {
$pageNum_rsBuildlist = $_GET['pageNum_rsBuildlist'];
}
$startRow_rsBuildlist = $pageNum_rsBuildlist * $maxRows_rsBuildlist;
mysql_select_db($database_connGrowl, $connGrowl);
if ($_GET['build']) {
$built = $_GET['build'];
$query_rsBuildlist = "SELECT * FROM growl_locos WHERE growl_locos.buildID LIKE '$built' ORDER BY growl_locos.LocoID ASC";
} else {
$query_rsBuildlist = "SELECT * FROM growl_locos ORDER BY LocoID ASC";}
$query_limit_rsBuildlist = sprintf("%s LIMIT %d, %d", $query_rsBuildlist, $startRow_rsBuildlist, $maxRows_rsBuildlist);
$rsBuildlist = mysql_query($query_limit_rsBuildlist, $connGrowl) or die(mysql_error());
$row_rsBuildlist = mysql_fetch_assoc($rsBuildlist);
if (isset($_GET['totalRows_rsBuildlist'])) {
$totalRows_rsBuildlist = $_GET['totalRows_rsBuildlist'];
} else {
$all_rsBuildlist = mysql_query($query_rsBuildlist);
$totalRows_rsBuildlist = mysql_num_rows($all_rsBuildlist);
}
$totalPages_rsBuildlist = ceil($totalRows_rsBuildlist/$maxRows_rsBuildlist)-1;
mysql_select_db($database_connGrowl, $connGrowl);
$query_rsLocations = "SELECT * FROM growl_buildloc ORDER BY locID ASC";
$rsLocations = mysql_query($query_rsLocations, $connGrowl) or die(mysql_error());
$row_rsLocations = mysql_fetch_assoc($rsLocations);
$totalRows_rsLocations = mysql_num_rows($rsLocations);
?>
The 'rsLocations' is used to select the locations, and 'rsBuildlist' is used to display the records.
I cannot see the error, perhaps someone else may be able to see it! Any advice would be much appreciated.
Thanks
Phil