Welcome Guest, Not a member yet? Register   Sign In
Selecting a particular row from a result_array()
#1

[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>&lt;?php echo $num_rows ?&gt; Search results found for '<em><strong>&lt;?php echo $keyword ?&gt;</strong></em>'</h3>

</div>&lt;!--end of subNav --&gt;

&lt;?php foreach ($q as $row):?&gt;
    
    <h2><a href="">&lt;?=$row->empName ?&gt;</a></h2>
    
    <table width="100%" class="results_table">
        <tr>
            <td width="15%"><strong>Contact: </strong></td>
            <td>&lt;?=$row->contact ?&gt;</td>
        </tr>
        <tr>
            <td><strong>Tel: </strong></td>
            <td>&lt;?=$row->tel ?&gt;</td>
        </tr>
        <tr>
            <td><strong>Email: </strong></td>
            <td>&lt;?=$row->email ?&gt;</td>
        </tr>
        <tr>
            <td><strong>Area of Interest: </strong></td>
            <td>&lt;?=$row->interestArea ?&gt;</td>
        </tr>
        <tr>
            <td><strong>Lead assigned to: </strong></td>
            <td>&lt;?=$row->linkAdviser ?&gt;</td>
        </tr>
        <tr>
            <td><strong>Lead source: </strong></td>
            <td>&lt;?=$row->leadSource ?&gt;</td>
        </tr>
        <tr>
            <td><strong>Lead Status: </strong></td>
            <td>&lt;?php echo $q_status->row($row->lead_status) ?&gt;</td>
        </tr>
    <table>
    
&lt;?php endforeach; ?&gt;


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
#2

[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....




Theme © iAndrew 2016 - Forum software by © MyBB