gpt4 book ai didi

php - 使用php在服务器端数据表中内连接

转载 作者:行者123 更新时间:2023-11-29 20:30:50 24 4
gpt4 key购买 nike

//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;
}

请帮帮我,我有 3 个表,所有表都有一个主键作为 table_id 如何使用服务器端数据表从 3 个表获取数据如何在此代码中实现联接查询。这里employee_City、employee_State 和employee_Pin 存储在第二个表中。雇用个人详细信息存储在第三个表中。如何连接所有表?

最佳答案

我刚刚获取了表城市、州、密码的虚拟名称..

尝试使用此查询:

$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";

关于php - 使用php在服务器端数据表中内连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39078714/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com