Welcome Guest, Not a member yet? Register   Sign In
Outputing a list from 3 tables
#1

[eluser]jwburnside[/eluser]
Hey everyone, I just trying to print out some data in a particular format, and I was hoping for a standard way of doing this with CI, utilizing OO principles. First let me describe my tables, a simple M:M relationship:

Candidate_table
- id_candidate
- name
Position_table
- id_position
- title
Candidate_positions
- id_position
- id_candidate

And I'd like to print my output like this:

HR Representatives
- Aaron Aaronson
- Bob Bobson
Janitors
- Charles Charleston
- Dave Davidson

etc...


My models reflect the corresponding database table, with an array of the table fields and methods to access them, along with any other methods to run related queries.

I can already create this format like this in my model:

Code:
$positions_query = $this->_db_model->query("SELECT id_position,title FROM positions");    

$positions_result = $positions_query->result();
            
$candidates_query = $this->_db_model->query("SELECT candidates.id_candidate,firstname, lastname, uploads, id_position FROM candidates INNER JOIN candidate_positions
ON candidate_positions.id_candidate = candidates.id_candidate
");          
$candidates_result = $candidates_query->result();
                        
$result_array = array('positions_result' => $positions_result,'candidates_result' => $candidates_result) ;
return $result_array;

This is obviously ugly and stupid. Is there a more OO approach? Any help would be appreciated.




Theme © iAndrew 2016 - Forum software by © MyBB