Napisano: 06 Nov 2012 19:12
Pozdrav,
Kako mogu podesiti stranicu sa rezultatima pretrage, imam npr polje cena, e sad kada ukucam tačnu cenu onda radi ali ja želim da bude cena do 10.000 npr, i da mi prikaže sva vozila koja su do 10.000
$maxRows_search = 5;
$pageNum_search = 0;
if (isset($_GET['pageNum_search'])) {
$pageNum_search = $_GET['pageNum_search'];
}
$startRow_search = $pageNum_search * $maxRows_search;
mysql_select_db($database_osszekotes, $osszekotes);
$expected = array( 'kategorija' => 'text',
'marka' => 'text',
'model' => 'text',
'godiste' => 'int',
'cijena' => 'int',
'ABS' => 'text')
;
$query_search = "SELECT * FROM products";
// Set a flag to indicate whether the query has a WHERE clause
$where = false;
// Loop through the associatiave array of expected search values
foreach ($expected as $var => $type) {
if (isset($_GET[$var])) {
$value = trim(urldecode($_GET[$var]));
if (!empty($value)) {
// Check if the value begins with > or <
// If so, use it as the operator, and extract the value
if ($value[0] == '>' || $value[0] == '<') {
$operator = $value[0];
$value = ltrim(substr($value, 1));
} elseif (strtolower($type) != 'like') {
$operator = '=';
}
// Check if the WHERE clause has been added yet
if ($where) {
$query_search .= ' AND ';
} else {
$query_search .= ' WHERE ';
$where = true;
}
// Build the SQL query using the right operator and data type
$type = strtolower($type);
switch($type) {
case 'like':
$query_search .= "`$var` LIKE " . GetSQLValueString('%' .
$value . '%', "text");
break;
case 'int':
case 'double':
case 'date':
$query_search .= "`$var` $operator " .
GetSQLValueString($value, "$type");
break;
default:
$query_search .= "`$var` = " . GetSQLValueString($value,
"$type");
}
}
}
}
$query_limit_search = sprintf("%s LIMIT %d, %d", $query_search, $startRow_search, $maxRows_search);
sve mi radi osim kada želim ubaciti u where cena < od 10.000 npr
mislim da je ovaj deo coda za to
if (!empty($value)) {
// Check if the value begins with > or <
// If so, use it as the operator, and extract the value
if ($value[0] == '>' || $value[0] == '<') {
$operator = $value[0];
$value = ltrim(substr($value, 1));
Dopuna: 06 Nov 2012 19:18
Ako neko zna neki tutorial za advanced search može i to
Dopuna: 06 Nov 2012 19:31
Da li treba prvo da definišem maximum i minimum price, taj deo me najviše interesuje
Dopuna: 07 Nov 2012 16:12
Vidim da sam pogrešio interesuje me da li mogu da ubacim u svoj code ovako nešto, nažalost array mi je slaba tačka pa bi bio zahvalan za malo pomoći ako neko može
//if user enters 0 in both price fields, set both prices to nothing
if($pricemin = 0 && $pricemax = 0){
$pricemin = '';
$pricemax = '';
}
//if user enters 0 in pricemin and nothing in pricemax, set pricemin to nothing
if($pricemin = 0 && $pricemax = ''){
$pricemin = '';
}
//if user enters a number in pricemin and nothing in pricemax, set pricemax to highest value
if($pricemin > 0 && $pricemax = ''){
$pricemax = '99999';
}
//if user enters 0 in pricemax and nothing in pricemin, set pricemax to nothing
if($pricemin = '' && $pricemax = 0){
$pricemax = '';
}
//if user enters 0 in pricemax and nothing in pricemin, set pricemin to nothing
if($pricemin = '' && ($pricemax != '' && $pricemax > 0)){
$pricemin = 0;
}
|