Poniżej prezentuje kod funkcji odpowiedzialnej na mojej stronie za wyszukiwanie.
Mam mały problem z tą funkcją, a mianowicie nie np. po wpisaniu zakresu pięter od 1 do 1 wyświetla mi że brak ogłoszeń, a powinien wyświetlić ogłoszenia nieruchomości znajdujących się na 1 piętrze.
Jak się wyszukuje z jakiegoś zakresu np. piętro od 1 do 2 to wyświetla ogłoszenia z tego zakresu.
Serwis znajduje się pod adresem m-dom.pl
Jeśli ktoś ma jakieś pomysły jak rozwiązać problem to czekam na info

Kod
function searchAction() {
// get db adapter and session data
$db = Zend_Registry::get('db');
$db->setFetchMode(Zend_Db::FETCH_OBJ);
$search = new Zend_Session_Namespace('search');
$settings = new SettingsTable;
$pageLimit = $settings->fetchRow('title = "pageLimit"');
// if isset post data then set new search variables
if($this->_request->isPost()) {
$search->where = NULL;
// set where
foreach($this->_request->getPost() as $name => $value)
$post[$name] = $value;
if(!empty($post['advertisementType']))
$search->where .= ('(advertisements.advertisementType = '.intval($post['advertisementType'])).') AND ';
if(!empty($post['propertyType']))
$search->where .= ('(advertisements.propertyType = '.intval($post['propertyType'])).') AND ';
if(!empty($post['province']))
$search->where .= ('(advertisements.province = '.intval($post['province'])).') AND ';
if(!empty($post['city']))
$search->where .= ('(advertisements.city LIKE "%'.$post['city'].'%"').') AND ';
if(!empty($post['street']))
$search->where .= ('(advertisements.street LIKE "%'.$post['street'].'%"').') AND ';
if(!empty($post['priceFrom']))
$search->where .= ('(advertisements.price > '.floatval($post['priceFrom'])).') AND ';
if(!empty($post['priceFor']))
$search->where .= ('(advertisements.price < '.floatval($post['priceFor'])).') AND ';
if(!empty($post['areaSizeFrom']))
$search->where .= ('(advertisements.areaSize > '.intval($post['areaSizeFrom'])).') AND ';
if(!empty($post['areaSizeFor']))
$search->where .= ('(advertisements.areaSize < '.intval($post['areaSizeFor'])).') AND ';
if(!empty($post['liczbapieterFrom']))
$search->where .= ('(advertisements.liczbapieter > '.intval($post['liczbapieterFrom'])).') AND ';
if(!empty($post['liczbapieterFor']))
$search->where .= ('(advertisements.liczbapieter < '.intval($post['liczbapieterFor'])).') AND ';
if(!empty($post['pietroFrom']))
$search->where .= ('(advertisements.pietro > '.intval($post['pietroFrom'])).') AND ';
if(!empty($post['pietroFor']))
$search->where .= ('(advertisements.pietro < '.intval($post['pietroFor'])).') AND ';
if(!empty($post['liczbapokoiFrom']))
$search->where .= ('(advertisements.liczbapokoi > '.intval($post['liczbapokoiFrom'])).') AND ';
if(!empty($post['liczbapokoiFor']))
$search->where .= ('(advertisements.liczbapokoi < '.intval($post['liczbapokoiFor'])).') AND ';
if(!empty($post['keyword']))
$search->where .= ('(advertisements.otherInfo LIKE "%'.$post['keyword'].'%"').') AND ';
if(!empty($post['nrofer']))
$search->where .= ('(advertisements.nrofer LIKE "%'.$post['nrofer'].'%"').') AND ';
$search->where = substr($search->where, 0, (strlen($search->where)-4));
}
if(!empty($search->where) && $this->_request->getParam('page') >= 1) {
// get count finded advertisements
$advertisements = new AdvertisementsTable;
$select = $advertisements->select();
$select->from($advertisements, 'count(id) as count')
->where($search->where);
$row = $advertisements->fetchRow($select);
$this->view->search = true;
if($row->count > 0) {
// create final query
$select = $db->select();
$select->from('advertisements', array('id', 'nrofer', 'liczbapieter', 'pietro', 'liczbapokoi', 'areaSize', 'areaSize', 'price', 'description', 'city', 'announceDate', 'promo'))
->joinInner('propertyTypes', 'propertyTypes.id = advertisements.propertyType', 'type as propertyType')
->joinInner('advertisementTypes', 'advertisementTypes.id = advertisements.advertisementType', 'type as advertisementType')
->joinInner('provinces', 'provinces.id = advertisements.province', 'province')
->joinLeft('images', 'images.advertisementId = advertisements.id', 'image')
->where($search->where)
->where('dayCounter > 0')
->group('id')
->order(array('promo DESC', 'announceDate DESC'))
->limit($pageLimit->value, ($this->_request->getParam('page')-1)*$pageLimit->value);
$result = $db->query($select);
$this->view->advertisements = $result->fetchAll();
// set pages parameters
$this->view->pagesLink = 'adv/search/';
$this->view->pagesCount = $row->count;
$this->view->pagesLimit = $pageLimit->value;
$this->view->pagesCurrent = $this->_request->getParam('page');
}
}
}
// get db adapter and session data
$db = Zend_Registry::get('db');
$db->setFetchMode(Zend_Db::FETCH_OBJ);
$search = new Zend_Session_Namespace('search');
$settings = new SettingsTable;
$pageLimit = $settings->fetchRow('title = "pageLimit"');
// if isset post data then set new search variables
if($this->_request->isPost()) {
$search->where = NULL;
// set where
foreach($this->_request->getPost() as $name => $value)
$post[$name] = $value;
if(!empty($post['advertisementType']))
$search->where .= ('(advertisements.advertisementType = '.intval($post['advertisementType'])).') AND ';
if(!empty($post['propertyType']))
$search->where .= ('(advertisements.propertyType = '.intval($post['propertyType'])).') AND ';
if(!empty($post['province']))
$search->where .= ('(advertisements.province = '.intval($post['province'])).') AND ';
if(!empty($post['city']))
$search->where .= ('(advertisements.city LIKE "%'.$post['city'].'%"').') AND ';
if(!empty($post['street']))
$search->where .= ('(advertisements.street LIKE "%'.$post['street'].'%"').') AND ';
if(!empty($post['priceFrom']))
$search->where .= ('(advertisements.price > '.floatval($post['priceFrom'])).') AND ';
if(!empty($post['priceFor']))
$search->where .= ('(advertisements.price < '.floatval($post['priceFor'])).') AND ';
if(!empty($post['areaSizeFrom']))
$search->where .= ('(advertisements.areaSize > '.intval($post['areaSizeFrom'])).') AND ';
if(!empty($post['areaSizeFor']))
$search->where .= ('(advertisements.areaSize < '.intval($post['areaSizeFor'])).') AND ';
if(!empty($post['liczbapieterFrom']))
$search->where .= ('(advertisements.liczbapieter > '.intval($post['liczbapieterFrom'])).') AND ';
if(!empty($post['liczbapieterFor']))
$search->where .= ('(advertisements.liczbapieter < '.intval($post['liczbapieterFor'])).') AND ';
if(!empty($post['pietroFrom']))
$search->where .= ('(advertisements.pietro > '.intval($post['pietroFrom'])).') AND ';
if(!empty($post['pietroFor']))
$search->where .= ('(advertisements.pietro < '.intval($post['pietroFor'])).') AND ';
if(!empty($post['liczbapokoiFrom']))
$search->where .= ('(advertisements.liczbapokoi > '.intval($post['liczbapokoiFrom'])).') AND ';
if(!empty($post['liczbapokoiFor']))
$search->where .= ('(advertisements.liczbapokoi < '.intval($post['liczbapokoiFor'])).') AND ';
if(!empty($post['keyword']))
$search->where .= ('(advertisements.otherInfo LIKE "%'.$post['keyword'].'%"').') AND ';
if(!empty($post['nrofer']))
$search->where .= ('(advertisements.nrofer LIKE "%'.$post['nrofer'].'%"').') AND ';
$search->where = substr($search->where, 0, (strlen($search->where)-4));
}
if(!empty($search->where) && $this->_request->getParam('page') >= 1) {
// get count finded advertisements
$advertisements = new AdvertisementsTable;
$select = $advertisements->select();
$select->from($advertisements, 'count(id) as count')
->where($search->where);
$row = $advertisements->fetchRow($select);
$this->view->search = true;
if($row->count > 0) {
// create final query
$select = $db->select();
$select->from('advertisements', array('id', 'nrofer', 'liczbapieter', 'pietro', 'liczbapokoi', 'areaSize', 'areaSize', 'price', 'description', 'city', 'announceDate', 'promo'))
->joinInner('propertyTypes', 'propertyTypes.id = advertisements.propertyType', 'type as propertyType')
->joinInner('advertisementTypes', 'advertisementTypes.id = advertisements.advertisementType', 'type as advertisementType')
->joinInner('provinces', 'provinces.id = advertisements.province', 'province')
->joinLeft('images', 'images.advertisementId = advertisements.id', 'image')
->where($search->where)
->where('dayCounter > 0')
->group('id')
->order(array('promo DESC', 'announceDate DESC'))
->limit($pageLimit->value, ($this->_request->getParam('page')-1)*$pageLimit->value);
$result = $db->query($select);
$this->view->advertisements = $result->fetchAll();
// set pages parameters
$this->view->pagesLink = 'adv/search/';
$this->view->pagesCount = $row->count;
$this->view->pagesLimit = $pageLimit->value;
$this->view->pagesCurrent = $this->_request->getParam('page');
}
}
}
Pozdrawiam i z góry dziękuję za pomoc.