$sql="SELECT user_id, user_fname, user_lname, telephone, primary_email, dept_name, created_date, st_name, emp_level_name
FROM ".$prefix."users_info,
".$prefix."support_departments,
/".$prefix."user_status,
".$prefix."company_user_levels
WHERE ".$prefix."users_info.dept_id=".$prefix."support_departments.dept_id,
".$prefix."users_info.user_st=".$prefix."user_status.user_st,
".$prefix."users_info.user_level=".$prefix."company_user_levels.emp_level_id
ORDER BY ".$sort_para." ";
$employee_info = $wpdb->get_results($sql);
答案 0 :(得分:0)
在WHERE语句中,用'#34;替换comas; AND":
$sql = "SELECT user_id, user_fname, user_lname, telephone, primary_email, dept_name, created_date, st_name, emp_level_name
FROM ${prefix}users_info, ${prefix}support_departments, ${prefix}user_status, ${prefix}company_user_levels
WHERE ${prefix}users_info.dept_id=${prefix}support_departments.dept_id AND ${prefix}users_info.user_st=${prefix}user_status.user_st AND ${prefix}users_info.user_level=${prefix}company_user_levels.emp_level_id
ORDER BY ".$sort_para;
$employee_info = $wpdb->get_results($sql);
答案 1 :(得分:0)
把" AND"放错了什么?或"或"条件之间的条款而不是逗号?
答案 2 :(得分:0)
您需要使用join来从多个表中获取数据,
FROM ".$prefix."users_info ui
join ".$prefix."user_status su on su.FOREIGNKEY = ui.PRIMARY
此外,在需要在每种情况之间使用AND或OR条件的情况下
WHERE ".$prefix."users_info.dept_id=".$prefix."support_departments.dept_id AND
".$prefix."users_info.user_st=".$prefix."user_status.user_st