Welcome Guest, Not a member yet? Register   Sign In
How to use multiple join in codeigniter
#3

(03-31-2018, 11:10 AM)apysan Wrote: I am trying to join three tables and get the required result from there for my use , I have been partially successfull in that but can not get the desired result.
Please help.

My issue is mentioned in details in the attached file.

Thanks

This is what I have done and expect, infact I have already send this as attached document.



When I run the following query:
    public function select_all_student() {
        $this->db->select('*');
        $this->db->FROM('tbl_student');
        $this->db->join('tbl_class', 'tbl_student.class_id = tbl_class.class_id');
        //$this->db->join('tbl_section', 'tbl_student.section_id = tbl_section.section_id');
        $this->db->order_by("tbl_student.student_id", "desc");
 
       It gives me the following output:
Array
(
    [0] => stdClass Object
        (
            [student_id] => 1
            [student_name] => SHANKAR DAYAL SHARMA
            [class_id] => 1
            [class_name] => ONE
            [section_id] => 1
            [section_name] =>
            [student_gurdian] => parent of sharkar dayal sharma
            [student_dob] => 03/13/2018
            [student_gender] => Male
            [student_blood_group] => B-
            [student_relegion] => Hinduism
            [student_email] => [email protected]
            [student_phone] => 3333333333, 6565656565, 8686868686
            [student_address] => address1
 
 
When I run the following query:
    public function select_all_student() {
        $this->db->select('*');
        $this->db->FROM('tbl_student');
        //$this->db->join('tbl_class', 'tbl_student.class_id = tbl_class.class_id');
        $this->db->join('tbl_section', 'tbl_student.section_id = tbl_section.section_id');
        $this->db->order_by("tbl_student.student_id", "desc");
 
 
It gives me the following output:
            [student_id] => 1
            [student_name] => SHANKAR DAYAL SHARMA
            [class_id] => 0
            [class_name] =>
            [section_id] => 1
            [section_name] => A
            [student_gurdian] => parent of sharkar dayal sharma
            [student_dob] => 03/13/2018
            [student_gender] => Male
            [student_blood_group] => B-
            [student_relegion] => Hinduism
            [student_email] => [email protected]
            [student_phone] => 3333333333, 6565656565, 8686868686
            [student_address] => address1
address2
 
 
I need this optput:
            [class_id] => 1
            [class_name] => ONE
            [section_id] => 1
            [section_name] => A
It is possible if I can retain the result of this two joins together
        $this->db->join('tbl_class', 'tbl_student.class_id = tbl_class.class_id');
        $this->db->join('tbl_section', 'tbl_student.section_id = tbl_section.section_id');
How to do that ?
 
More details
Tbl_student


1
student_id[img=1x1]file:///C:/Users/arjun/AppData/Local/Temp/msohtmlclip1/01/clip_image001.gif[/img]
int(11)


No
None

AUTO_INCREMENT
2
student_name
varchar(50)
utf8_general_ci

No
None


3
class_id
int(11)


No
None


4
class_name
varchar(10)
utf8_general_ci

No
None


5
section_id
int(11)


No
None


6
section_name
varchar(10)
utf8_general_ci

No
None


7
student_gurdian
varchar(100)
utf8_general_ci

No
None


8
student_dob
varchar(50)
utf8_general_ci

No
None


9
student_gender
varchar(10)
utf8_general_ci

No
None


 
 
 
 
 
 
 
Tbl_class
1
ONE
11
2B-FETCHED
1
2bd
pkd --------------- 11
1
2
TWO
9
2B-FETCHED
2
2bd
DT ------------------------------ 9
1
3
THREE
10
2B-FETCHED
3
2bd
KU --------------- >>  10
1
4
FOUR
12
2B-FETCHED
4
2bd
SANDEEP SAHA -------------------------------> 1...
0
5
FIVE
13
2B-FETCHED
5
2bd
                               4                 ...
1
 
 
 
And
Tbl_section

1
A
11
not reqd field
0

sec_CAT
45
2
B
10
not reqd field
0

BCAT
50
3
C
12
not reqd field
0

BCAT222
40
4
D
11
not reqd field
0

DDD
23
5
E
0
not reqd field
0

2222
44
6
F
12
not reqd field
0



 
Reply


Messages In This Thread
RE: How to use multiple join in codeigniter - by apysan - 04-01-2018, 05:43 AM



Theme © iAndrew 2016 - Forum software by © MyBB