Selecting a particular row from a result_array() - El Forum - 04-09-2010
[eluser]bcarter[/eluser]
Hi
I HATE being a noob!!! Can somebody please help? On the Lead status table row (in the Result_view) it displayed the id of the lead status instead of the value so I am trying to put that value into an array from another query so that it displays what I want. (I know that sentence probably doesn't make sense but hopefully the following will)
By using the code below I get an error message saying...
Quote:Fatal error: Call to a member function result_array() on a non-object in C:\xampp\htdocs\CodeIgniter\application\views\results_view.php on line 42
Model
Code: 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();
}
function get_num_rows($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');
$num_rows = $q->num_rows();
return $num_rows;
}
function lead_status() {
$q_status = $this->db->query('SELECT lead_status FROM lead_status');
return $q_status->result_array();
}
}
View
Code: <h3><?php echo $num_rows ?> Search results found for '<em><strong><?php echo $keyword ?></strong></em>'</h3>
</div><!--end of subNav -->
<?php foreach ($q as $row):?>
<h2><a href=""><?=$row->empName ?></a></h2>
<table width="100%" class="results_table">
<tr>
<td width="15%"><strong>Contact: </strong></td>
<td><?=$row->contact ?></td>
</tr>
<tr>
<td><strong>Tel: </strong></td>
<td><?=$row->tel ?></td>
</tr>
<tr>
<td><strong>Email: </strong></td>
<td><?=$row->email ?></td>
</tr>
<tr>
<td><strong>Area of Interest: </strong></td>
<td><?=$row->interestArea ?></td>
</tr>
<tr>
<td><strong>Lead assigned to: </strong></td>
<td><?=$row->linkAdviser ?></td>
</tr>
<tr>
<td><strong>Lead source: </strong></td>
<td><?=$row->leadSource ?></td>
</tr>
<tr>
<td><strong>Lead Status: </strong></td>
<td><?php echo $q_status->row($row->lead_status) ?></td>
</tr>
<table>
<?php endforeach; ?>
Controller
Code: 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 {
$keyword = $this->input->post('keyword');
$data['keyword'] = $keyword;
$data['page_title'] = "Search Results";
$this->load->model('Results_model');
$data['q'] = $this->Results_model->get_results($keyword);
$data['num_rows'] = $this->Results_model->get_num_rows($keyword);
$data['q_status'] = $this->Results_model->lead_status();
$this->load->view('head', $data);
$this->load->view('results_view', $data);
}
}
}
Can someone help please?!
Cheers
Selecting a particular row from a result_array() - El Forum - 04-09-2010
[eluser]n0xie[/eluser]
I have the sneaking suspicion you need a JOIN on the lead_status table, but it's very hard to figure out what you're trying to do. You described your problem pretty cryptic....
|