codeigniter join 2 table data
It doesn't matter what table is first... Simply:
<?php
$this->db->select('t1.name, t2.something, t3.another')
->from('table1 as t1')
->where('t1.id', $id)
->join('table2 as t2', 't1.id = t2.id', 'LEFT')
->join('table3 as t3', 't1.id = t3.id', 'LEFT')
->get();
?>
Codeigniter join two tables in model
You should try this one.
$this->db->select('*')
->from('lists')
->join('list_items', 'list_items.list_id = lists.id')
->where('list_id', $id);
$query = $this->db->get();
Reference
- query_builder
CodeIgniter join two tables
Try this in controller and see whats the result.Also,show us if you are getting any error and make sure there is data in your table :).
Controller
function getall(){
$this->load->model('result_model');
$data['query'] =$this->result_model->result_getall();
print_r($data['query']);
die();
$this->load->view('result_view', $data);
}
how codeigniter join two tables to have both Id columns
try this:
$this->db->select('*,comment.id as comment_id,users.user_id as user_id,users.name as user_name');
$this->db->from('comment');
$this->db->where('user_id', $user_id);
$this->db->join('users', 'users.user_id = comment.id');
$this->db->order_by("comment.id", "asc");
return $this->db->get()->result_array();
it return all user and comment
table data
may be this codeigniter query help you out
Codeigniter join two table based on two join conditions
Try:
$this->db->select("Query.*, uf.fullname as firstMD, us.fullname as secondMD");
$this->db->join('Users uf', 'uf.id = Query.attendingMD');
$this->db->join('Users us', 'us.id = Query.secondAttendingMD');
$this->db->where('Query.isCompleted', 1);
$query = $this->db->get('Query');
return $query->result_array();
How to join 2 tables in codeigniter PHP?
Go to folder "Models" That´s where you´ll do all your CRUD operations to the database.
For example, you can create a model file called "guest_profile_model.php"
Now you open that file and paste the code bellow:
<?php
class guest_profile_model extends CI_Model {
public function select($company_id) {
$this->db->query("select * from `guest_info` INNER JOIN `guest_profile` ON guest_info.g_uid = guest_profile.g_uid WHERE guest_info.company_id = ".$company_id." LIMIT 2");
$result = $this->db->query($query);
return $result->result_object();
}
}
That´s it, now from within your controller you just need to load and call it.
Example:
$this-> load-> model('guest_profile_model ');
$company_id = 1;
$queryResult = $this -> guest_profile_model ->select(company_id);
print_r($queryResult);
Notice that the query return is going to be an object, that is because of the "result_object" in the model, you can change that to be an array if you want to.
Related Topics
Laravel 5 - Session Doesn't Work
Share Session Between Two Websites
Upload Images Through PHP Using Unique File Names
File_Get_Contents Is Not Working for Some Url
PHP - Make Multi-Dimensional Associative Array from a Delimited String
Different Recipients Based on Product Category in Woocommerce Email Notification
PHP Flush Stopped Flushing in Iis7.5
Set the Option Available for Select Based on Another Select PHP
PHP Replace All Spaces with Hyphens
PHP Fopen() Error: Failed to Open Stream: Permission Denied
Using a Variable as an Operator
What's the Best and Easiest Way to Populate a Dropdown Based on Another Dropdown
Difference(When Being Applied to My Code) Between Int(10) and Int(12)
Laravel 5 Multiple Download File
PHP - Upload Picture and Display on Page
Implementing Oauth2 Login, Fatal Error: Class 'Google_Service' Not Found