Forum Moderators: coopster
Excuse me in advance for the long winded explanation:
I have a PHP page with a single form on containing two fields, I am posting this info using the get method to another page which will query a mysql database and display the required fields.
The problem I have is only one of the variables seems to be working properly, this is the code I have.
<?php require_once('Connections/connGlobal.php');?>
<?php
$currentPage = $HTTP_SERVER_VARS["PHP_SELF"];
$maxRows_rsMirror = 10;
$pageNum_rsMirror = 0;
if (isset($HTTP_GET_VARS['pageNum_rsMirror'])) {
$pageNum_rsMirror = $HTTP_GET_VARS['pageNum_rsMirror'];
}
$startRow_rsMirror = $pageNum_rsMirror * $maxRows_rsMirror;
$colname_rsMirror = "1";
if (isset($HTTP_GET_VARS['txtmodel'])) {
$colname_rsMirror = (get_magic_quotes_gpc())? $HTTP_GET_VARS['txtmodel'] : addslashes($HTTP_GET_VARS['txtmodel']);
}
mysql_select_db($database_connGlobal, $connGlobal);
$query_rsMirror = sprintf("SELECT * FROM mirror WHERE model LIKE '%%%s%%'", $colname_rsMirror);
$query_limit_rsMirror = sprintf("%s LIMIT %d, %d", $query_rsMirror, $startRow_rsMirror, $maxRows_rsMirror);
$rsMirror = mysql_query($query_limit_rsMirror, $connGlobal) or die(mysql_error());
$row_rsMirror = mysql_fetch_assoc($rsMirror);
if (isset($HTTP_GET_VARS['totalRows_rsMirror'])) {
$totalRows_rsMirror = $HTTP_GET_VARS['totalRows_rsMirror'];
} else {
$all_rsMirror = mysql_query($query_rsMirror);
$totalRows_rsMirror = mysql_num_rows($all_rsMirror);
}
$totalPages_rsMirror = ceil($totalRows_rsMirror/$maxRows_rsMirror)-1;
$queryString_rsMirror = "";
if (!empty($HTTP_SERVER_VARS['QUERY_STRING'])) {
$params = explode("&", $HTTP_SERVER_VARS['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_rsMirror") == false &&
stristr($param, "totalRows_rsMirror") == false) {
array_push($newParams, $param);
}
}
if (count($newParams)!= 0) {
$queryString_rsMirror = "&" . implode("&", $newParams);
}
}
$queryString_rsMirror = sprintf("&totalRows_rsMirror=%d%s", $totalRows_rsMirror, $queryString_rsMirror);
?>
The variables are called txtmake and txtmodel, they are transfering across from the previous page, I can see them in the address bar like this
[mydomain.com...]
It is turning out to be an epic.
Any pointers would be appreciated.
Regards
CurlyK
Whats happening is:
I have the two fields in the form
txtmodel
txtmake
I add data to both fields and it transfers the data across as I said in the address bar, so I assume the data is going across to the results page
It does retrieve data from the database but it is only searching on the basis of the txtmodel info.
To explain better shall I sticky you the url?
The site is not live, its a spare domain I have for testing things.
Thankyou:)
CurlyK
see this
$query_rsMirror = sprintf("SELECT * FROM mirror WHERE model LIKE '%%%s%%'", $colname_rsMirror);
$query_limit_rsMirror = sprintf("%s LIMIT %d, %d", $query_rsMirror, $startRow_rsMirror, $maxRows_rsMirror);
as is the script doesn't look for $HTTP_GET_VARS['txtmake'] at all that I can see. Do you select make and model 100% of the time or can you select one or the other as well?
example queries would be
existing one
SELECT * FROM mirror WHERE model LIKE '%fiesta%'
if always selecting both and they need to match
SELECT * FROM mirror WHERE model LIKE '%fiesta%' AND make LIKE '%ford%'
if they can match one or the other
SELECT * FROM mirror WHERE model LIKE '%fiesta%' OR make LIKE '%ford%'
if they have the option to only select one field for searching you will have to construct your query based on which values have been set.
[edited by: jatar_k at 9:13 pm (utc) on Dec. 11, 2002]
The user does not as yet have to fill in both text boxes, but if they fill in only the txtmodel box I get zero results from the database?
I intend to make the form in such a way that if only one box is filled in it will ask you for the other info before submitting, I haven't got that far yet.
If I understand this correctly the error is in mysql query?
Or am I missing a variable?
I'm sorry to appear such a gimp but I have only been doing this for two weeks ;)
Thank you
That is about as in depth as you could possibly need.
some links that might help you get started
PHP Manual [php.net]
Predefined Variables [php.net] (get and post arrays)
PHP Function Reference [php.net]
PHP MYSQL Functions [php.net]
for your mysql queries
MySQL Documentation [mysql.com]
String Comparison Functions [mysql.com]
SELECT Syntax [mysql.com]