Код: Выделить всё
$all = $this->input->get('all');
if($all)
{
$keywords = $this->input->get('search');
$data['search'] = $keywords;
$this->session->set_flashdata('search', $keywords);
$query = "SELECT * FROM `investOffers`, `news`";
$counts = "SELECT count(*) as count FROM `investOffers`, `news`";
$first = false;
if($keywords)
{
$data['keywords'] = $keywords;
$this->session->set_flashdata('keywords', $keywords);
$keywords = explode(" ", $keywords);
foreach($keywords as $k)
{
if(!$first)
{
$query .= " WHERE investOffers.desc LIKE '% ".$k." %' OR investOffers.title LIKE '% ".$k." %'";
$query .= " OR news.desc LIKE '% ".$k." %' OR news.title LIKE '% ".$k." %'";
$counts .= " WHERE investOffers.desc LIKE '% ".$k." %' OR investOffers.title LIKE '% ".$k." %'";
$counts .= " OR news.desc LIKE '% ".$k." %' OR news.title LIKE '% ".$k." %'";
$first = true;
}
else
{
$query .= " OR investOffers.desc LIKE '% ".$k." %' OR investOffers.title LIKE '% ".$k." %'";
$query .= " OR news.desc LIKE '% ".$k." %' OR news.title LIKE '% ".$k." %'";
$counts .= " OR investOffers.desc LIKE '% ".$k." %' OR investOffers.title LIKE '% ".$k." %'";
$counts .= " OR news.desc LIKE '% ".$k." %' OR news.title LIKE '% ".$k." %'";
}
}
}
$page = $this->uri->segment(2);
if($page)
{
$query .= " ORDER BY investOffers.date DESC LIMIT ".$page.", 10";
$counts .= " ORDER BY investOffers.date DESC LIMIT 10";
}
else
{
$query .= " ORDER BY investOffers.date DESC LIMIT 10";
$counts .= " ORDER BY investOffers.date DESC LIMIT 10";
}
$data['query'] = $this->db->query($query);
$counts = $this->db->query($counts);
foreach($counts->result() as $q)
{
$count = $q->count;
break;
}
$config['base_url'] = base_url().'/search';
$config['prev_link'] = false;
$config['next_link'] = false;
$config['last_link'] = false;
$config['first_link'] = false;
$config['suffix'] = '?'.http_build_query($_GET, '', "&");
$config['cur_tag_open'] = '[b]';
$config['cur_tag_close'] = '[/b]';
$from = intval($this->uri->segment(2));
$config['per_page'] = 10;
$config['num_links'] = 5;
$config['uri_segment'] = 2;
$config['total_rows'] = $count;
$this->pagination->initialize($config);
$data['pager'] = $this->pagination->create_links();
$data['content'] = $this->load->view(SITE.'search', $data, true);
$this->load->view(SITE.'layout', $data);
return true;
}
Это приложение CodeIgniter, и приведенный выше код — мой метод контроллера. Я не использую модели, потому что не хочу открывать много файлов.
Подробнее здесь: https://stackoverflow.com/questions/107 ... arch-words
Мобильная версия