//define index of column
$columns = array(
0 =>'id',
1 =>'employee_name',
2 => 'employee_salary',
3 => 'employee_age'
4 =>'employee_City',
5 => 'employee_State',
6 => 'employee_Pin'
);
$where = $sqlTot = $sqlRec = "";
if( !empty($params['search']['value']) ) {
$where .=" WHERE ";
$where .=" ( employee_name LIKE '".$params['search']['value']."%' ";
$where .=" OR employee_salary LIKE '".$params['search']['value']."%' ";
$where .=" OR employee_age LIKE '".$params['search']['value']."%' )";
}
// getting total number records without any search
$sql = "SELECT * FROM `employee` ";
$sqlTot .= $sql;
$sqlRec .= $sql;
//concatenate search sql if value exist
if(isset($where) && $where != '') {
$sqlTot .= $where;
$sqlRec .= $where;
}
Help me please, I have 3 tables, all tables has a primary key as table_id how to get data from 3 tables using server side datatables how to implement join query in this code. Here employee_City, employee_State and employee_Pin are stored in second table. Employ personal details Stored in third table. How to join all tables?
I have just take dummy name of table city , state , pincode ..
Try with this query :
$sql = "SELECT id, employee_name, employee_salary, employee_age, employee_City, employee_State, employee_Pin FROM employee LEFT JOIN city ON employee.cityID = city.id LEFT JOIN state ON employee.stateID = state.id LEFT JOIN pincode ON employee.pincodeid = pincode.id ";
if( !empty($params['search']['value']) ) {
$sql .=" WHERE ";
$sql .=" ( employee_name LIKE '%".$params['search']['value']."%' ";
$sql .=" OR employee_salary LIKE '%".$params['search']['value']."%' ";
$sql .=" OR employee_age LIKE '%".$params['search']['value']."%' )";
}
$sql.=" ORDER BY employee_name";
These links will help you make join query:
https://www.sitepoint.com/understanding-sql-joins-mysql-database/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.