avinashse
avinashse

Reputation: 1460

sql query joining three tables

I have to select category name,description,id from the tbl_ticket_categories from that selected id I have to find the user_id from the tbl_ticket_repliers and from that user_id I have to find the username from the tbl_users.

Finally selected attributes should be category_name, description and username . What I am doing my view is :-

    function editCategory($site_referers_id) {
        $this->db->select('tbl_ticket_categories.category_name,tbl_ticket_categories.description,tbl_users.username,tbl_ticket_repliers.user_id');
        $this->db->where('site_referers_id',$site_referers_id);
        $this->db->join('tbl_ticket_repliers','tbl_ticket_repliers.category_id = tbl_ticket_categories.id');
        $this->db->join('tbl_users','tbl_users.id = tbl_ticket_repliers.user_id');
        return $this->db->get('tbl_ticket_categories');
    }

In my view, when I am doing <?php var_dump($categories); ?> it showing :-

object(CI_DB_mysql_result)[32]
  public 'conn_id' => resource(43, mysql link persistent)
  public 'result_id' => resource(81, mysql result)
  public 'result_array' => 
    array
      empty
  public 'result_object' => 
    array
      empty
  public 'custom_result_object' => 
    array
      empty
  public 'current_row' => int 0
  public 'num_rows' => int 1
  public 'row_data' => null

How to do this query :(

my tables are :-

tbl_ticket_categories(id , category_name , description , site_referers_id)

tbl_ticket_repliers(id , user_id , category_id , site_referer_id)

tbl_users(id , role_id , username , password )

SOLVED

Upvotes: 0

Views: 138

Answers (2)

naveen
naveen

Reputation: 1068

function editCategory($site_referers_id) {
        $this->db->select('tbl_ticket_categories.category_name,tbl_ticket_categories.description,tbl_users.username,tbl_ticket_repliers.user_id');
        $this->db->where('site_referers_id',$site_referers_id);
        $this->db->join('tbl_ticket_repliers','tbl_ticket_repliers.category_id = tbl_ticket_categories.id');
        $this->db->join('tbl_users','tbl_users.id = tbl_ticket_repliers.user_id');
        return $this->db->get('tbl_ticket_categories')->result_array();
    }

add result_array() above query and print_r() instead of var_dump u see the result

Upvotes: 2

avinashse
avinashse

Reputation: 1460

this is correct query, the problem was I wrote result_array instead of result_array() and next time I deleted whole sentence and used var_dump().

sorry

Upvotes: 0

Related Questions