Codeigniter Tutorials
- What is codeigniter?
- Application_Architecture
- MVC Architecture
- HMVC Architecture
- Codeigniter Configuration
- Remove index.php from url in codeigniter
- MVC Concept
- View
- Alternate PHP Syntax for View Files
- Routing
- Codeigniter URL
- Get Current URL
- Previous page URL get
- Seo Friendly URL
- Slug Create in codeigniter
- What is _remap() function
- Remove controller name from url in codeigniter
- Codeigniter Controller Class
- Class Constructor
- GET $ POST method in Codeigniter
- Models
- Basepath, Apppath, FCPATH
- URI Segment
- Page Redirect
- Helper class
- Custom Helper class
- Form Helper
- Common Helper Functions
- Common Function
- Array Problems
- Call controller in Helper
- Add active class to menu using Helper class
- Custom Library
- Custom Library Example
- when to use get_instance()
- Codeigniter Hook
- how to work inline css in codeigniter
- Custom 404 page
- 404 custom error page
- Create custom config file in codeigniter
- How to set and get config item value
- How to Speed Up CodeIgniter App?
- Codeigniter Functions
- Session
- cookies
- How to Set & Get Tempdata in Codeigniter
- flash messages in Codeigniter
- Flashdata
- Encryption and Decryption In CodeIgniter
- Codeigniter security
- csrf token form security
- Password Hashing
- Form Validation
- Custom Validation
- Registration Form with validation
- Server Side Form Validation
- Validate Select Option Field
- Date Format Validation
- Date Format change in codeigniter
- Date Functions
- DOB Validation
- CI CRUD
- User SignUp
- User Login
- User Logout
- Login Account
- Login form with RememberMe
- Login Form with session
- User change password
- Change Password with Callback Validation to Check Old Password
- Forgot password
- Reset password
- Insert data in database
- Fetch data from database
- Update data in database
- Delete data in database
- File Upload
- Image Upload with resize Image
- Upload Multiple file and images
- Upload Multiple images with CRUD
- File and image update
- Upload Image Using Ajax.
- Email Send
- Email Send Using Email library
- Email Send Using SMTP Gmail
- Notification send
- store data in json format in DB
- Json parse
- Fetch data Using Ajax with Json data
- How to Show data Using Ajax with Json parse
- Get JSON Data from PHP Script using jQuery Ajax
- Insert data Using Ajax
- Submit data Using Ajax with form validation
- How to show data Using Ajax in codeigniter
- Insert & Update Using Ajax
- Registration Form With Validation Using Ajax in codeigniter
- Delete data Using Ajax Confirmation
- Delete All data Using checkbox selection
- Ajax CSRF Token
- Ajax Post
- Ajax serverside form validation
- Contact form using AJAX with form validation
- DataTable Using Ajax dynamically
- DataTables pagination using AJAX with Custom filter
- DataTables AJAX Pagination with Search and Sort in codeigniter
- DataTables in Codeigniter using Ajax
- Ajax Custom Serarch
- Ajax Live Data Search using Jquery PHP MySql
- Ajax Custom Serarch and sorting in datatable
- Dynamic Search Using Ajax
- Autocomplete using jquery ajax
- Jquery Ajax Autocomplete Search using Typeahead
- Dynamic Dependent Dropdown Using Ajax
- Dynamic Dependent Dropdown list Using Ajax
- Dynamic Dependent Dropdown in codeigniter using Ajax
- ajax username/email availability check using JQuery
- Check Email Availability Using Ajax
- Data Load on mouse scroll
- Ajax CI Pagination
- Pagination in codeigniter
- Ajax Codeigniter Pagination
- email exists or not using ajax with json
- CRUD using AJAX With Modal popup in CI
- Add / Show Data on modal popup using Ajax
- Modal popup Validation using Ajax
- Data show on Modal popup Using Ajax
- Add / Remove text field dynamically using jquery ajax
- How to Add/Delete Multiple HTML Rows using JavaScript
- Delete Multiple Rows using Checkbox
- Multiple Checkbox value
- Form submit using jquery Example
- REST & SOAP API
- Multi-Language implementation in CodeIgniter
- How to pass multiple array in view
- Captcha
- create zip file and download
- PhpOffice PhpSpreadsheet Library (Export data in excel sheet)
- data export in excel sheet
- Excel File generate in Codeigniter using PHPExcel
- Dompdf library
- tcpdf library
- Html table to Excel & docs download
- CI Database Query
- Database Query
- SQL Injection Prevention
- Auth Model
- Join Mysql
- Tree View in dropdown option list
- OTP Integration in codeigniter
- curl post
- download file using curl
- Sweet Alert
- Sweet alert Delete & Success
- Log Message in Codeigniter
- Menu & Submenu show dynamically
- Set Default value in input box
- Cron Jobs
- Stored Procedure
- Display Loading Image when AJAX call is in Progress
- Send SMS
- IP Address
- Codeigniter Tutorialspoint
- Website Link
- How To Create Dynamic Xml Sitemap In Codeigniter
- Paypal Payment Integration
- Get Latitude and Longitude From Address in Codeigniter Using google map API
- How To Create Simple Bar Chart In Codeigniter Using AmCharts?
- dynamic Highcharts in Codeigniter
- Barcode in Codeigniter
- Codeigniter Interview Questions
- Project
Mysql Join
Normal Join Query
$this->db->select('*');
$this->db->from('ittutorial');
$this->db->join('class', 'class.id = tutorial.id');
$query = $this->db->get();
$result = $query->result();
###################### OR ########################
$qry = "SELECT * FROM ittutorial JOIN class ON class.id = tutorial.id";
$query = $this->db->query($qry);
$result = $query->result();
return $result;
Normal Join
$this->db->select('tbl_user.username,tbl_user.userid,tbl_usercategory.typee');
$this->db->from('tbl_user');
$this->db->join('tbl_usercategory','tbl_usercategory.usercategoryid=tbl_user.usercategoryid');
$query=$this->db->get();
$data=$query->result_array();
SELECT `tbl_user`.`username`, `tbl_user`.`userid`, `tbl_usercategory`.`type`
FROM (`tbl_user`)
JOIN `tbl_usercategory` ON `tbl_usercategory`.`usercategoryid`=`tbl_user`.`usercategoryid
Join With Condition
$this->db->select('tbl_user.username,tbl_user.userid,tbl_usercategory.typee');
$this->db->from('tbl_user');
$this->db->join('tbl_usercategory','tbl_usercategory.usercategoryid=tbl_user.usercategoryid');
$this->db->where('tbl_usercategory','admin');
$query=$this->db->get();
$data= $query->result_array();
SELECT `tbl_user`.`username`, `tbl_user`.`userid`, `tbl_usercategory`.`type`
FROM (`tbl_user`)
JOIN `tbl_usercategory` ON `tbl_usercategory`.`usercategoryid`=`tbl_user`.`usercategoryid`
Inner Join
Used Two table Inner Join in codeigniter
$this->db->select('tbl_user.username,tbl_user.userid,tbl_usercategory.type');
$this->db->from('tbl_user');
$this->db->join('tbl_usercategory','tbl_usercategory.usercategoryid=tbl_user.usercategoryid','inner');
$query=$this->db->get();
SELECT `tbl_user`.`username`, `tbl_user`.`userid`, `tbl_usercategory`.`typee`
FROM (`tbl_user`)
INNER JOIN `tbl_usercategory` ON `tbl_usercategory`.`usercategoryid`=`tbl_user`.`usercategoryid`
Used Three table Inner Join in codeigniter
File Name :
$this->db->select('username,amount, configdescription');
$this->db->from('tbl_user');
$this->db->join('tbl_usersubscription','tbl_usersubscription.userid=tbl_user.userid','inner');
$this->db->join('tbl_subscription',
'tbl_usersubscription.subscription_config_id=tbl_subscription.configid','inner');
Multiple table Join using query string in codeigniter
File Name :
$sql="select np.*,nwip.i_techcommtt_id, nwip.added_on, nwip.added_by, nwip.i_dept_id, td.Abbreviations, td.ID, tc.CommitteeNumber from nwip_techcommtt_allocation nwip
inner join proposals np on np.pki_id=nwip.i_nwip_id
inner join Tech_Comm tc on tc.ID=nwip.i_techcommtt_id
inner join Tech_Dep td on td.ID=tc.DepartmentID
where nwip.i_techcommtt_id in(".$this->db->escape_str($commttid).") AND nwip.i_status=1 AND np.status='1';";
$query = $this->db->query($sql);
$rows = $query->result_array();
return $rows;
SELECT `username`, `amount`, `configdescription`
FROM (`tbl_user`)
INNER JOIN `tbl_usersubscription` ON `tbl_usersubscription`.`userid`=`tbl_user`.`userid`
INNER JOIN `tbl_subscription` ON `tbl_usersubscription`.`subscription_config_id`=`tbl_subscription`.`configid`
Left Join
Used Two table Left Join in codeigniter
$this->db->select('tbl_user.username,tbl_user.userid,tbl_usercategory.type');
$this->db->from('tbl_user');
$this->db->join('tbl_usercategory','tbl_usercategory.usercategoryid=tbl_user.usercategoryid','Left');
$query=$this->db->get();
SELECT `tbl_user`.`username`, `tbl_user`.`userid`, `tbl_usercategory`.`typee`
FROM (`tbl_user`)
Left JOIN `tbl_usercategory` ON `tbl_usercategory`.`usercategoryid`=`tbl_user`.`usercategoryid`
Right Join
Used Two table Right Join in codeigniter
File Name :
$this->db->select('tbl_user.username,tbl_user.userid,tbl_usercategory.type');
$this->db->from('tbl_user');
$this->db->join('tbl_usercategory','tbl_usercategory.usercategoryid=tbl_user.usercategoryid','Right');
$query=$this->db->get();
SELECT `tbl_user`.`username`, `tbl_user`.`userid`, `tbl_usercategory`.`typee`
FROM (`tbl_user`)
Right JOIN `tbl_usercategory` ON `tbl_usercategory`.`usercategoryid`=`tbl_user`.`usercategoryid`
File Name :
File Name :
$this->db->select('*');
$this->db->from('table1');
$this->db->join('table2', 'table1.id = table2.id');
$this->db->join('table3', 'table1.id = table3.id');
$query = $this->db->get();
Join Multiple Tables
File Name :
$this->db->select('*');
$this->db->from('users');
$this->db->join('profile_image', 'profile_image.user_id = users.id');
$this->db->join('city', 'city.user_id = users.id','left');
$this->db->join('post', 'post.user_id = users.id','left');
$this->db->join('friends', 'friends.user_id = users.id','left');
$this->db->where('users.id', $id);
$query = $this->db->get();
// Result
Select *from users
join profile_image on profile_image.user_id = users.id
left join city on city.user_id = users.id
left join post on post.user_id = users.id
left join friends on friends.user_id = users.id
where users.id = $id
search Data in multiple table with Join
File Name :
public function get_search_key($key)
{
$this->db->select("*");
$this->db->from('student_details');
$this->db->like('rollno', $key);
$this->db->or_like('first_name', $key);
$this->db->or_like('last_name', $key);
$this->db->or_like('class', $key);
$this->db->or_like('section', $key);
$this->db->or_like('parents_details.father_firstname',$key);
$this->db->or_like('parents_details.father_lastname',$key);
$this->db->join('parents_details','parents_details.sid = student_details.sid');
//$this->db->order_by('sid', 'DESC');
$query = $this->db->get();
return $query->result();
}
File Name :
public function getStudentInfo($studentid){
$query = $this->db->select("st.id, st.name, st.class, mk.maths, mk.science")
->from("students as st")
->join("marks as mk", "mk.student_id = st.id", "inner")
->where("st.id", $studentId)
->get();
return $query->result();
}
Note: $this->db->select(‘*’) means you are getting all columns from both tables
File Name :
this->db->select('*');
$this->db->from('users');
$this->db->join('comments','comments.user_id = users.u_id');
$this->db->get();
Multiple Table
File Name :
$this->db->select('*')
->from('users')
->join('comments','comments.user_id = users.u_id')
->join('city','city.user_id = users.u_id')
->get();
Using where clause
File Name :
$this->db->select('*')
->from('users')
->where('users.u_id',1)
->join('comments','comments.user_id = users.u_id')
->join('city','city.user_id = users.u_id')
->get();
File Name :
$this->db->query("select table1.ud_id,table1.ud_date,table1.up_lat_profit_date,table1.ud_currency
,sum(table1.ud_amount*table3.dp_percentage/100) as profit
from table1
JOIN `table2` ON `table2`.`deposit_id` = `table1`.`ud_id`
JOIN `table3` ON `table3`.`dp_id` = `table2`.`daily_profit_id`
where `table1`.`ud_status` = 1
AND `table3`.`dp_status` = 1
AND `table1`.`user_plan_id` = $up_id
AND table2.pr_status = 1
group by table1.ud_id");
Join
File Name :
$this->db->select('Table1.*, Table2.*');
$this->db->from('Table1');
$this->db->join('Table2', 'Table2.id = Table1.id');
$query = $this->db->get();
//Produces:
SELECT `Table1`.*, `Table2`.* FROM `Table1`
JOIN `Table2` ON `Table2`.`id` = `Table1`.`id`
Inner Join
File Name :
$this->db->select('Table1.*, Table2.*');
$this->db->from('Table1');
$this->db->join('Table2', 'Table2.id = Table1.id','inner');
$query = $this->db->get();
//Produces:
SELECT `Table1`.*, `Table2`.* FROM `Table1`
INNER JOIN `Table2` ON `Table2`.`id` = `Table1`.`id`
Conditional Join
File Name :
$this->db->select('Table1.*, Table2.*');
$this->db->from('Table1');
$this->db->join('Table2', 'Table2.id = Table1.id');
$this->db->where('Table1.field_name','field_value');
$query = $this->db->get();
//Produces:
SELECT `Table1`.*, `Table2`.* FROM `Table1`
JOIN `Table2` ON `Table2`.`id` = `Table1`.`id`
WHERE `Table1`.`field_name` = ‘field_value’
Join Table with alias
File Name :
$this->db->select('u.id, u.username, c.name');
$this->db->from('user as u');
$this->db->join('companies as c', 'u.company_id = c.id');
$this->db->where('LOWER(u.username)=', strtolower('foobar'));
$query = $this->db->get();
Send second parameter FALSE to not escape special characters.
$this->db->select('u.id, u.username, c.name', false);
Join Multiple Table with Alias
File Name :
$this->db->select('u.id,u.name,pi.image,p.post,f.id as fid');
$this->db->from('users as u');
$this->db->join('profile_image as pi ', 'pi.user_id = u.id');
$this->db->join('city as c', 'c.user_id = u.id','left');
$this->db->join('post as p ', 'p.user_id = u.id','left');
$this->db->join('friends as f ', 'f.user_id = u.id','left');
$this->db->where('u.id', $id);
$query = $this->db->get();
The above example will produce output something like this-
// Select u.id,u.name,pi.image,p.post,f.id as fid from users
join profile_image as pi on profile_image.user_id = users.id
left join city as c on c.user_id = u.id
left join post as p on p.user_id = u.id
left join friends as f on f.user_id = u.id
where u.id = $id
Normal Join
$this->db->select('tbl_user.username,tbl_user.userid,tbl_usercategory.typee');
$this->db->from('tbl_user');
$this->db->join('tbl_usercategory','tbl_usercategory.usercategoryid=tbl_user.usercategoryid');
$query=$this->db->get();
$data=$query->result_array();
Join With Condition
$this->db->select('tbl_user.username,tbl_user.userid,tbl_usercategory.typee');
$this->db->from('tbl_user');
$this->db->join('tbl_usercategory','tbl_usercategory.usercategoryid=tbl_user.usercategoryid');
$this->db->where('tbl_usercategory','admin');
$query=$this->db->get();
$data= $query->result_array();
$this->db->select('*');
$this->db->from('ittutorial');
$this->db->join('class', 'class.id = tutorial.id');
$this->db->where(array('class.id' => 786));
$query = $this->db->get();
$result = $query->result();
###################### OR ########################
$qry = "SELECT * FROM ittutorial
JOIN class ON class.id = tutorial.id
where class.id = 786";
$query = $this->db->query($qry);
$result = $query->result();
return $result;
Inner Join
$this->db->select('tbl_user.username,tbl_user.userid,tbl_usercategory.type');
$this->db->from('tbl_user');
$this->db->join('tbl_usercategory','tbl_usercategory.usercategoryid=tbl_user.usercategoryid','inner');
$query=$this->db->get();
SELECT `tbl_user`.`username`, `tbl_user`.`userid`, `tbl_usercategory`.`typee`
FROM (`tbl_user`)
INNER JOIN `tbl_usercategory` ON `tbl_usercategory`.`usercategoryid`=`tbl_user`.`usercategoryid`
Used Three table Inner Join in codeigniter
$this->db->select('username,amount, configdescription');
$this->db->from('tbl_user');
$this->db->join('tbl_usersubscription','tbl_usersubscription.userid=tbl_user.userid','inner');
$this->db->join('tbl_subscription',
'tbl_usersubscription.subscription_config_id=tbl_subscription.configid','inner');
SELECT `username`, `amount`, `configdescription`
FROM (`tbl_user`)
INNER JOIN `tbl_usersubscription` ON `tbl_usersubscription`.`userid`=`tbl_user`.`userid`
INNER JOIN `tbl_subscription` ON `tbl_usersubscription`.`subscription_config_id`=`tbl_subscription`.`configid`
Left Join
$this->db->select('tbl_user.username,tbl_user.userid,tbl_usercategory.type');
$this->db->from('tbl_user');
$this->db->join('tbl_usercategory','tbl_usercategory.usercategoryid=tbl_user.usercategoryid','Left');
$query=$this->db->get();
SELECT `tbl_user`.`username`, `tbl_user`.`userid`, `tbl_usercategory`.`typee`
FROM (`tbl_user`)
Left JOIN `tbl_usercategory` ON `tbl_usercategory`.`usercategoryid`=`tbl_user`.`usercategoryid`
Right Join
$this->db->select('tbl_user.username,tbl_user.userid,tbl_usercategory.type');
$this->db->from('tbl_user');
$this->db->join('tbl_usercategory','tbl_usercategory.usercategoryid=tbl_user.usercategoryid','Right');
$query=$this->db->get();
SELECT `tbl_user`.`username`, `tbl_user`.`userid`, `tbl_usercategory`.`typee`
FROM (`tbl_user`)
Right JOIN `tbl_usercategory` ON `tbl_usercategory`.`usercategoryid`=`tbl_user`.`usercategoryid`
Inner Join in codeigniter
File Name :
/*
$sql="select np.*,nwip_alloc.i_techcommtt_id, nwip_alloc.added_on, nwip_alloc.added_by, nwip_alloc.i_dept_id, td.Abbreviations, td.ID, tc.CommitteeNumber from tech_commtt_allocation nwip_alloc
inner join propos np on np.pki_id=nwip_alloc.i_nwip_id
inner join TechComm tc on tc.ID=nwip_alloc.techcommttid
inner join TechDep td on td.ID=tc.DepID
where nwip_alloc.i_techcommtt_id in (".$this->db->escape_str($commttid).") AND nwip_alloc.i_status=1;";
$query = $this->db->query($sql);
$rows = $query->result_array();
return $rows;
*/
######################### OR ############################
$this->db->select('np.*,nwip_alloc.i_techcommtt_id, nwip_alloc.added_on, nwip_alloc.added_by, nwip_alloc.i_dept_id, td.Abbreviations, td.ID, tc.CommitteeNumber');
$this->db->from('techcomt as nwip_alloc');
$this->db->join('propos as np', 'np.pki_id=nwip_alloc.i_nwip_id','inner');
$this->db->join('Techcomm as tc', 'tc.ID=nwip_alloc.techcommid','inner');
$this->db->join('TechDep as td', 'td.ID=tc.DepID','inner' );
$this->db->where_in('nwip_alloc.i_techcommtt_id',$commttid,false);
$this->db->where('nwip_alloc.i_status', '1');
$query = $this->db->get();
//echo $this->db->last_query();
$rows = $query->result_array();
return $rows;
Join with multiple Table
File Name :
$this->db->select('*');
$this->db->from('ittutorial');
$this->db->join('class', 'class.id = tutorial.id');
$this->db->join('comments', 'comments.id = tutorial.id');
// $this->db->where(array('class.id' => 786));
$query = $this->db->get();
$result = $query->result();
###################### OR ########################
$qry = "SELECT * FROM ittutorial
JOIN class ON class.id = tutorial.id
JOIN comments ON comments.id = tutorial.id
// where class.id = 786";
$query = $this->db->query($qry);
$result = $query->result();
return $result;
Left Join
File Name :
$this->db->select('*');
$this->db->from('ittutorial');
$this->db->join('class', 'class.id = tutorial.id','left');
$this->db->join('comments', 'comments.id = tutorial.id','left');
$query = $this->db->get();
$result = $query->result();
###################### OR ########################
$qry = "SELECT * FROM ittutorial
LEFT JOIN class ON class.id = tutorial.id
LEFT JOIN comments ON comments.id = tutorial.id
$query = $this->db->query($qry);
$result = $query->result();
return $result;
RIGHT JOIN
File Name :
$this->db->select('*');
$this->db->from('ittutorial');
$this->db->join('class', 'class.id = tutorial.id','RIGHT');
$this->db->join('comments', 'comments.id = tutorial.id','RIGHT');
$this->db->ORDER_BY('comments.id', ASC);
$query = $this->db->get();
$result = $query->result();
###################### OR ########################
$qry = "SELECT * FROM ittutorial
RIGHT JOIN class ON class.id = tutorial.id
RIGHT JOIN comments ON comments.id = tutorial.id
$query = $this->db->query($qry);
$result = $query->result();
return $result;
File Name :
$this->db->select('cd.*, edu.*, gt.*, cd.i_status as can_status');
$this->db->from('candetails as cd');
$this->db->join('edudetails as edu','edu.fk_id=cd.pki_id','left');
$this->db->join('gate as gt','gt.fk_id=cd.pki_id','left');
$this->db->where($where);
$this->db->group_by('edu.fk_id');
//$this->db->where('cd.i_status','3');
//$this->db->where('cd.category', $category);
// $this->db->where('cd.discipline', $discipline);
$query=$this->db->get();
// echo $this->db->last_query();
//$response = $query->result_array();
return $result = $query->result();
File Name :
File Name :
File Name :