Hello
Perhaps I should explain that better.
I Have set up an on-line vehicle showroom with MySql, PHP and DWMX. All works great. I have a horizontal looper which displayed 8 vehicles at a time and a 'total pages 1 2 ...' link so if there are say, 10, vehicles then there will be a link to the 'next page' etc. It all works fine. I added a search page on which the visitor can enter either the make, colour, model, milage or price. The visitor first selects from a list the catagory he wishes to search from, say colour, then in another field enteres the value of his selection, say, red. On submit he is passed along to the search results page.
On this page I pass the contents of $_POST['value'] to some variables like $sc then I do some simple validating on these fields.
The horizontal looper on that page then displays 8 returned records in two rows. Works great for 8 records or less. Say there are 9 returned results for colour, red. As expected there will be a 'page 1 of 2' link. Click on the page 2 to see the last record and I have a missing image (red cross) and no description.
I have narrowed this down to the fact that when the visitor clicks on the next page link the a PHP_SELF command is executed which I presume runs the page again, but this time the value of the variables the user entered in the form field have dissapeared and the looper of course cannot display anything!!
I think the problem is because I've got the form validating stuff at the top of the search returns page, I think I may need to validate it before getting to the search resilts.
The code is below. (Is this the correct way to post code BTW?)
Anyway I'm still learning PHP and hope someone can help me with this one.
Thanks all
Rob
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php require_once('Connections/forge.php'); ?>
<?php
// set temporary variables
$desLen=25; // Length of vehicle description under thumbnails
$selectStr="";
$st=$POST['searchTerm']; // Search term i.e. Ford, Blue, Golf
$sc=$POST['searchCat']; // Search term i.e. Make, Model, Price, Colour
$sv=$_POST['searchVal']; // Search value i.e. 12000 (miles) or 6000 (£)
$svUnder=($sv-1000); // Set tolerance value to search between
$svOver=($sv+1000);
if ($svUnder<=0) {
$svUnder=0;
}
if (empty($sc)) { // if Catagory is empty set it to Make and set Search term to space
$sc="make" and $st=" ";
}
if ($sc=="milage" || $sc=="price") { // Set search term to null if visitor is searching for price or milage
if (isset($st)) {
$st=null;
}
}
if (empty($st)) { // Set SQL select string
$selectStr="$sc >= $svUnder AND $sc <= $svOver"; // Set to this if Search term is empty i.e. Value is set
} else {
$selectStr="$sc LIKE '%$st%'"; // Otherwise set to this if term is set i.e. search for ford, red
}
$maxRows_rssitResults = 8;
$pageNum_rssitResults = 0;
if (isset($HTTP_GET_VARS['pageNum_rssitResults'])) {
$pageNum_rssitResults = $HTTP_GET_VARS['pageNum_rssitResults'];
}
$startRow_rssitResults = $pageNum_rssitResults * $maxRows_rssitResults;
mysql_select_db($database_forge, $forge);
$query_rssitResults = "SELECT * FROM vehicles WHERE ($selectStr)";
$query_limit_rssitResults = sprintf("%s LIMIT %d, %d", $query_rssitResults, $startRow_rssitResults, $maxRows_rssitResults);
$rssitResults = mysql_query($query_limit_rssitResults, $forge) or die(mysql_error());
$row_rssitResults = mysql_fetch_assoc($rssitResults);
if (isset($HTTP_GET_VARS['totalRows_rssitResults'])) {
$totalRows_rssitResults = $HTTP_GET_VARS['totalRows_rssitResults'];
} else {
$all_rssitResults = mysql_query($query_rssitResults);
$totalRows_rssitResults = mysql_num_rows($all_rssitResults);
}
$totalPages_rssitResults = ceil($totalRows_rssitResults/$maxRows_rssitResults)-1;
$queryString_rssitResults = "";
if (!empty($HTTP_SERVER_VARS['QUERY_STRING'])) {
$params = explode("&", $HTTP_SERVER_VARS['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_rssitResults") == false &&
stristr($param, "totalRows_rssitResults") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_rssitResults = "&" . implode("&", $newParams);
}
}
$queryString_rssitResults = sprintf("&totalRows_rssitResults=%d%s", $totalRows_rssitResults, $queryString_rssitResults);
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="detail.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
body {
background-image: url(assets/vw_back.gif);
background-repeat: no-repeat;
}
-->
</style>
<script language="JavaScript" type="text/javascript">
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->
</script>
</head>
<body>
<?php if ($totalRows_rssitResults == 0) { // Show if recordset empty ?>
<div id="NoRecords" style="position:absolute; left:198px; top:116px; width:273px; z-index:8">No
vehicles found, please try again</div>
<?php } // Show if recordset empty ?>
<table width="565" border="0" cellspacing="0" cellpadding="0" bgcolor="#990000">
<tr>
<td><img src="assets/spacer.gif" alt="" width="625" height="1" /></td>
</tr>
</table>
<?php if ($totalRows_rssitResults > 0) { // Show if recordset not empty ?>
<div id="layNavstatus" style="position:absolute; width:200px; z-index:2; left: 16px; top: 275px;">
<p></p>
Page <strong><?php echo $pageNum_rssitResults+1; ?></strong> of <strong><?php echo $totalPages_rssitResults+1; ?></strong> </div>
<?php } // Show if recordset not empty ?>
<?php if ($totalRows_rssitResults > 0) { // Show if recordset not empty ?>
<div id="layNavbar" style="position:absolute; width:200px; z-index:1; left: 178px; top: 264px;">
<table cellspacing="0" id="tblPagenav">
<tr>
<td align="right"><img src="assets/spacer.gif" width="100" height="10" alt=""></td>
<td><img src="assets/spacer.gif" width="10" height="10" alt=""></td>
<td><img src="assets/spacer.gif" width="100" height="10" alt=""></td>
</tr>
<tr>
<td align="right"><?php
$pageNum_tmp = max(0, $pageNum_rssitResults-1);
for ($pageNum_i=$pageNum_tmp+1;$pageNum_i<=$pageNum_rssitResults;$pageNum_i++) { //previous pages
?>
<a href="<?php printf ("%25s?pageNum_rssitResults=%25d%25s", $HTTP_SERVER_VARS["PHP_SELF"], $pageNum_i-1, $queryString_rssitResults); ?>"><?php echo $pageNum_i; ?></a>
<?php
} //end previous pages
?>
</td>
<td><strong><?php echo $pageNum_rssitResults+1; ?></strong></td>
<td><?php
$pageNum_tmp = min($pageNum_rssitResults+1+1, $totalPages_rssitResults+1);
for ($pageNum_i=$pageNum_rssitResults+2;$pageNum_i<=$pageNum_tmp;$pageNum_i++) { // next pages
?>
<a href="<?php printf ("%25s?pageNum_rssitResults=%25d%25s", $HTTP_SERVER_VARS["PHP_SELF"], $pageNum_i-1, $queryString_rssitResults); ?>"><?php echo $pageNum_i; ?></a>
<?php
} //end next pages
?>
</td>
</tr>
</table>
</div>
<?php echo ($totalRows_rssitResults);?>
<?php } // Show if recordset not empty ?>
<?php if ($totalRows_rssitResults > 0) { // Show if recordset not empty ?>
<div id="layInfo" style="position:absolute; width:724px; z-index:3; left: 16px; top: 247px;">Click
on a link to view the vehicles' specification. You will also be able to print
a copy of this data sheet.</div>
<?php } // Show if recordset not empty ?>
<div id="layHomepage" style="position:absolute; width:150px; z-index:4; left: 480px; top: 275px;">
<p class="spec"><a href="frame_content.php">Back to home page</a></p>
</div>
<div id="searchCriteria" style="position:absolute; width:313px; z-index:5; left: 8px; top: 2px; height: 15px;">Search
results for <?php echo "$sc" . " : " . "$sv" . " " . "$st";?> </div>
<?php if ($totalRows_rssitResults > 0) { // Show if recordset not empty ?>
<div id="layLooper" style="position:absolute; width:140px; z-index:6; left: 8px; top: 20px;">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<?php
do { // horizontal looper
?>
<td><table cellspacing="0" id="tblThumb">
<tr>
<td><img src="<?php echo $row_rssitResults['thumb_url']; ?>"></td>
</tr>
<tr>
<td class="spec"><a href="vehicleDet.php?detailID=<?php echo$row_rssitResults['ID'];?>" target="_blank">
<?php
$tmpStr=$row_rssitResults['model'];
echo (substr("$tmpStr",0,$desLen));?>
</a></td>
</tr>
</table>
</td>
<?php
$row_rssitResults = mysql_fetch_assoc($rssitResults);
if (!isset($nested_rssitResults)) {
$nested_rssitResults= 1;
}
if (isset($row_rssitResults) && is_array($row_rssitResults) && $nested_rssitResults++%4==0) {
echo "</tr><tr>";
}
} while ($row_rssitResults); //end horizontal looper
?>
</tr>
</table>
</div>
<?php } // Show if recordset not empty ?>
<div id="Layer1" style="position:absolute; width:199px; z-index:7; left: 125px; top: 2px; height: 18px;"><?php echo ("$ss"); ?></div>
<br />
</body>
</html>
<?php
mysql_free_result($rssitResults);
?>