0

I am try to join with two table.
This is my simple sql query:

$sql = "SELECT windows_users_image_upload.*, `windows_users_info`.`display`
        FROM `windows_users_image_upload`,`windows_users_info`
        WHERE `windows_users_info`.`user_id` = `windows_users_image_upload`.`user_id`
            AND " . $field . "=" . $value;

It works fine, but I want to use CodeIgniter's query builder methods; something like this:

$this->db->select("windows_users_image_upload.*,windows_users_info.display");
$this->db->from("windows_users_info,windows_users_image_upload");
$this->db->where("windows_users_image_upload.".$field,$value);
$this->db->limit($takeTuple, $startTuple);
$this->db->join("windows_users_image_upload,windows_users_image_upload.user_id = windows_users_info.user_id");
$result = $this->db->get()->result();

but it's showing me this error:

Message: Missing argument 2 for CI_DB_active_record::join()

How can I fix this?

2

2 Answers 2

1

This is how you use a join in CodeIgniter:

$this->db->select('*');
$this->db->from('blogs');
$this->db->join('comments', 'comments.id = blogs.id');

$query = $this->db->get();

// Produces:
// SELECT * FROM blogs
// JOIN comments ON comments.id = blogs.id1

You can see it in the User-Guide of CodeIgniter.

http://ellislab.com/codeigniter/user-guide/database/active_record.html#select

Sign up to request clarification or add additional context in comments.

Comments

1

You have to remove de second table in from command:

Example:

 $this->db->select('windows_users_image_upload.*,windows_users_info.display');
 $this->db->from('windows_users_info');
 $this->db->join("windows_users_image_upload","windows_users_image_upload.user_id = windows_users_info.user_id");
 $this->db->where("windows_users_image_upload.".$field,$value);

 $query = $this->db->get();

1 Comment

$this->db->select("windows_users_image_upload.*,windows_users_info.display"); $this->db->from("windows_users_info"); $this->db->where("windows_users_image_upload.".$field,$value); $this->db->limit($takeTuple, $startTuple); $this->db->join("windows_users_image_upload","windows_users_image_upload.user_id = windows_users_info.user_id"); $result = $this->db->get()->result();

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.