Hello to everyone!
I use this code for my search engine:
I don't know how to change it if I want to search 'price' between two values from two input boxes? You know, I want to find all records with prices between 100$ and 500$...
I'm not a webmaster.
Please help me.
Thank You in advance!
I use this code for my search engine:
<?php
$search_array = array('usluga', 'branza', 'price', 'doradca');
$where = array();
foreach ( $search_array as $search ) {
$value = JRequest::getVar($search, '' , 'post');
if ( $value ) {
$where[] = " $search LIKE '%$value%' ";
}
}
if ( !empty($where) ) {
echo " WHERE ".implode(' AND ', $where);
}?>I don't know how to change it if I want to search 'price' between two values from two input boxes? You know, I want to find all records with prices between 100$ and 500$...
I'm not a webmaster.
Please help me.
Thank You in advance!
Hi Creamdealer,
Add these extra line to the where box
Bob
Add these extra line to the where box
$min_value = JRequest::getVar('min_value, '' , 'post');
if ( $min_value ) {
$where[] = " `value` > '$min_value'";
}
$max_value = JRequest::getVar('max_value, '' , 'post');
if ( $max_value ) {
$where[] = " `value` <= '$max_value'";
}You'll need to change min_value, max_value & value to match whatever the inputs and columns are called in your form and table.Bob
Thank You very much Bob, but I still have some problems. I made smth like this:
But it doesn't work. When I use search, the values "kwota" are the same...
<?php
$search_array = array('usluga', 'branza', 'kwota', 'doradca', );
$where = array();
$min_value = JRequest::getVar('kwota', '' , 'post');
if ( $min_value ) {
$where[] = " 'min' > '$min_value'";
}
$max_value = JRequest::getVar('kwota', '' , 'post');
if ( $max_value ) {
$where[] = " 'max' <= '$max_value'";
}
foreach ( $search_array as $search ) {
$value = JRequest::getVar($search, '' , 'post');
if ( $value ) {
$where[] = " $search LIKE '%$value%' ";
}
}
if ( !empty($where) ) {
echo " WHERE ".implode(' AND ', $where);
}?>But it doesn't work. When I use search, the values "kwota" are the same...
Hi CreamDealer,
You have straight quotes '' round max and min, in my version they are backticks `max` `min`
You may need t check the logic too.
Bob
You have straight quotes '' round max and min, in my version they are backticks `max` `min`
You may need t check the logic too.
Bob
OK, Thank You VERY VERY MUCH!
Now it sorts but it sorts alphabeticaly. So if I search beetween 1500 and 3000 it shows me 199 too...
What can be wrong?
Now it sorts but it sorts alphabeticaly. So if I search beetween 1500 and 3000 it shows me 199 too...
What can be wrong?
This topic is locked and no more replies can be posted.
