CodeIgniter Forums
Problem with join ! - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Problem with join ! (/showthread.php?tid=42728)

Pages: 1 2


Problem with join ! - El Forum - 06-17-2011

[eluser]NETACCESS[/eluser]
Hi guys and sorry for my bad english,

Okay so i'm new in CI, i'm develloping my first application with it, it's great, i had no problem until now.

I have two tables (projetsPortfolio & imagesPortfolio).

First one contain the projects and the other the images of the projects. I use a 'project_id' column in the imagesPortfolio table for join in my query.

Here is the code :

Code:
function getlastReal(){

          $this->db->order_by('projetsPortfolio.id','DESC');
          $this->db->limit(3);
          $this->db->join('imagesPortfolio', 'projetsPortfolio.id = imagesPortfolio.project_id');
          $query = $this->db->get('projetsPortfolio');
        if($query->num_rows() > 0){

            foreach($query->result() as $row){
                $data[] = $row;
            }
            return $data;

        }

    }

it's work but it return me only one row of imagesPortfolio. But each project have severals images...

Okay guys, i hope you can help me.

Thanks in advance. Wink


Problem with join ! - El Forum - 06-17-2011

[eluser]brucebat[/eluser]
Would it not be better to create a View in your database that contains all the tables you need and then query the view?

Would be more secure too.


Problem with join ! - El Forum - 06-17-2011

[eluser]osci[/eluser]
try
Code:
$this->db->join('imagesPortfolio', 'imagesPortfolio.project_id = projetsPortfolio.id', 'left');



Problem with join ! - El Forum - 06-17-2011

[eluser]osci[/eluser]
[quote author="brucebat" date="1308324502"]Would it not be better to create a View in your database that contains all the tables you need and then query the view?

Would be more secure too.[/quote]

More secure as to what, he is using active record!


Problem with join ! - El Forum - 06-17-2011

[eluser]NETACCESS[/eluser]
Thank you.

But same :'( ... only one row in imagesPortfolio.

Any other idea ?

thanx


Problem with join ! - El Forum - 06-17-2011

[eluser]NETACCESS[/eluser]
Oh something is strange, if i got two images to get, i will have oly one row in imagesPortfolio but two in my projectPortfolio.

I dont know how to explain with my poor english Confused


Problem with join ! - El Forum - 06-17-2011

[eluser]brucebat[/eluser]
[quote author="osci" date="1308324553"][quote author="brucebat" date="1308324502"]Would it not be better to create a View in your database that contains all the tables you need and then query the view?

Would be more secure too.[/quote]

More secure as to what, he is using active record![/quote]


Well from what I was taught in University it is always good to use views as a layer of separation between the front end and the database?

What do you think? Smile


Problem with join ! - El Forum - 06-17-2011

[eluser]vitoco[/eluser]
can you post the resulting query ?


Problem with join ! - El Forum - 06-17-2011

[eluser]osci[/eluser]
[quote author="brucebat" date="1308339071"][quote author="osci" date="1308324553"][quote author="brucebat" date="1308324502"]Would it not be better to create a View in your database that contains all the tables you need and then query the view?

Would be more secure too.[/quote]

More secure as to what, he is using active record![/quote]


Well from what I was taught in University it is always good to use views as a layer of separation between the front end and the database?

What do you think? Smile[/quote]

Code separation doesn't have to do with security.

Edit: sorry for hijacking the thread.


Problem with join ! - El Forum - 06-17-2011

[eluser]brucebat[/eluser]
[quote author="osci" date="1308365149"][quote author="brucebat" date="1308339071"][quote author="osci" date="1308324553"][quote author="brucebat" date="1308324502"]Would it not be better to create a View in your database that contains all the tables you need and then query the view?

Would be more secure too.[/quote]

More secure as to what, he is using active record![/quote]


Well from what I was taught in University it is always good to use views as a layer of separation between the front end and the database?

What do you think? Smile[/quote]

Code separation doesn't have to do with security.

Edit: sorry for hijacking the thread.[/quote]


My apologies for confusion, I was talking about Database views

http://en.wikipedia.org/wiki/View_(database)