Welcome Guest, Not a member yet? Register   Sign In
Do I use inner join for this?
#1

[eluser]blinger2008[/eluser]
I have 2 tables in a database, one for projects, and one for sub-projects. Both have a 'category' field. I display all my projects on one page, and when I click on one, I want the sub-projects under that category to show up on the next page. Do I need to use an inner join or is there another way to do this?
#2

[eluser]dUspan[/eluser]
it depends on what you want to display.

but if it only requires sub projects then you dont need to use join with this Big Grin

for more advice kindly pls be specific on what you want to acquire.cheers Big Grin
#3

[eluser]blinger2008[/eluser]
I have a list of projects displayed, and when you click on one, i want it to display the sub projects in that category. i have this code:
Code:
//model
function get_record($id){
        $this->db->where('category',$id);
        $query = $this->db->get('projects_inner');
        return $query->result();
        }  

//controller
    function category(){
        $data = array();
        
        if($this->uri->segment(3)) {
        $data['records'] =$this->project_model->get_record($this->uri->segment(3));
        } else {
        if($query = $this->project_model->get_record()){
            $data['records'] = $query;
            }
    }
        $this->masterpage->addContentPage('head/default', 'head');
        $this->masterpage->addContentPage('content/project_category', 'content', $data);
        $this->masterpage->show();
        
        }

//view
<table class="projects"><tr>
&lt;?php if(isset($records)) : foreach($records as $row) :?&gt;


<td><a >category); ?&gt;"><img >projectImageUrl);?&gt;" /></a><br/>
<strong>&lt;?php echo $row->category; ?&gt;
         &lt;?php $is_logged_in = $this->session->userdata('is_logged_in');
        
            if(!isset($is_logged_in) || $is_logged_in != false)
            {
            
            echo anchor("index.php/projects/delete/$row->id", 'x',array('class'=>'delete'));
        ?&gt;
             &lt;?php
            }
            ?&gt;
</strong></td>
</tr>
&lt;?php endforeach; ?&gt;
</table>
#4

[eluser]marjune[/eluser]
the other way is sub query, but prefer join because sub query is perform much time than joining!




Theme © iAndrew 2016 - Forum software by © MyBB