When the user types in the search PHP it should find the questions that have category id of 1
I store my category id in a column in question called "tags" it's serialized of couse because the user may have chosen multiple tags / categories.
The category table name is category and columns "category_id" "name" "status"
a:2:{i:0;s:1:"1";i:1;s:1:"4";}
I can search for questions fine but cannot search if it is a category they are searching for.
Any idea's and examples thanks for your time
Controller
Search.php (Size: 1.59 KB / Downloads: 1)
I store my category id in a column in question called "tags" it's serialized of couse because the user may have chosen multiple tags / categories.
The category table name is category and columns "category_id" "name" "status"
a:2:{i:0;s:1:"1";i:1;s:1:"4";}
I can search for questions fine but cannot search if it is a category they are searching for.
Any idea's and examples thanks for your time
PHP Code:
public function get_questions($search) {
$this->db->select('*');
$this->db->from($this->db->dbprefix . 'question');
$this->db->like('title', $search);
$query1 = $this->db->get();
if ($query->num_rows() > 0) {
foreach ($query->result_array() as $key) {
$data[] = array(
'question_id' => $key['question_id'],
'title' => $key['title'],
'votes' => $key['votes'],
'answers' => $this->answer_model->count_answers($key['question_id']),
'views' => ''
);
}
}
return $data;
}
Controller
PHP Code:
<?php
class Search extends MY_Controller {
public function __construct() {
parent::__construct();
$this->load->library('user_agent');
if ($this->input->get('q') == FALSE) {
redirect($this->agent->referrer());
}
$this->load->model('answers/answer_model');
}
public function index() {
if ($this->input->post('search')) {
$q = str_replace('+', ' ', $this->input->get('q'));
$data['title'] = 'Questions ' . "'" . $q . "'";
$question_results = $this->get_questions($q);
$data['questions'] = array();
if (isset($question_results)) {
foreach ($results as $result) {
$data['questions'][] = array(
'question_id' => $result['question_id'],
'title' => $result['title'],
'votes' => $result['votes'],
'answers' => $this->answer_model->count_answers($result['question_id']),
'views' => ''
);
}
}
$data['page'] = 'search/search_results';
$this->load->view($this->config->item('config_template') . '/template/template_view', $data);
}
}
}
Search.php (Size: 1.59 KB / Downloads: 1)