[eluser]bcarter[/eluser]
Hi
Noob here, I'm trying to do a simple search page with a results page, it's all working except the most important part....querying the database of the keyword.
Here is the Search controller
Code:
<?php
class Search extends Controller {
function Search() {
parent::Controller();
}
function index() {
$data['page_title'] = "Search the database";
$this->load->library('form_validation');
$this->form_validation->set_rules('keyword', 'Keyword', 'required');
if ($this->form_validation->run() == FALSE) {
$this->load->view('search_view', $data);
} else {
redirect('results');
}
}
}
Here is the Search_view
Code:
<?php echo form_open('search') ?>
<p><?php echo form_input('keyword',set_value('keyword')); ?> <?php echo form_submit('submit','Search'); ?></p>
<p><?php echo form_error('keyword'); ?></p>
</form>
....and the Result Model
Code:
<?php
class Results_model extends Model {
function Results_model() {
parent::Model();
}
function get_results($keyword) {
$this->db->like('empName', $keyword);
$this->db->or_like('contact', $keyword);
$this->db->or_like('linkAdviser', $keyword);
$this->db->or_like('leadSource', $keyword);
$q = $this->db->get('details');
return $q->result();
}
}
...the Result controller
Code:
<?php
class Results extends Controller {
function Results() {
parent::Controller();
}
function index() {
$keyword = $this->input->post('keyword');
$data['page_title'] = "Search Results";
$this->load->model('Results_model');
$data['q'] = $this->Results_model->get_results($keyword);
$this->load->view('head', $data);
$this->load->view('results_view', $data);
}
}
and finally the result view
Code:
<?php foreach ($q as $row):?>
<h3><a href=""><?=$row->empName ?></a></h3>
<strong>Contact: <?=$row->contact ?></strong><br />
<strong>Tel: <?=$row->tel ?></strong><br />
<strong>Email: <?=$row->email ?></strong><br />
<strong>Area of Interest: <?=$row->interestArea ?></strong><br />
<strong>Lead assigned to: <?=$row->linkAdviser ?></strong><br />
<strong>Lead source: <?=$row->leadSource ?></strong><br />
<strong>Lead Status: <?=$row->lead_status ?></strong><br /><br />
<?php endforeach; ?>
When I click 'Search' it performs a query without a keyword and so returns all records from the database. The way I'm thinking is that it is not picking up the 'keyword' and assigning it to the $keyword variable in the results controller.
Can somebody point me in the right direction? Please remember I'm a CodeIgniter noob.
Many thanks for your assistance!!!