如何在代码点火器中使用条件?我必须将此查询转换为codeigniter格式请帮助。
$search = "%$search%";
$sql = "SELECT tickerr_tickets.*, tickerr_users2.name as agent_name, tickerr_ticket_departments.name as department_name, CASE WHEN guest_name != '' THEN guest_name ELSE tickerr_users1.name END AS client_final_name FROM tickerr_tickets INNER JOIN tickerr_ticket_departments ON tickerr_tickets.department=tickerr_ticket_departments.id LEFT JOIN tickerr_users tickerr_users1 ON tickerr_tickets.userid = tickerr_user1.id LEFT JOIN tickerr_users tickerr_users2 ON tickerr_tickets.agentid = tickerr_users2.id WHERE `status`=1 AND `agentid`!=0 (`tickerr_tickets`.`id` LIKE ? OR `tickerr_tickets`.`date` LIKE ? OR `last_update` LIKE ? OR `subject` LIKE ? OR `content` LIKE ? OR `tickerr_ticket_departments`.`name` LIKE ? OR (CASE WHEN guest_name != '' THEN guest_name ELSE tickerr_users.name END) LIKE ? OR `tickerr_users`.`username` LIKE ?) ORDER BY `$order_by` $order LIMIT $starting,$rows";
$query = $this->db->query($sql, array($search, $search, $search, $search, $search, $search, $search, $search));
1条答案
按热度按时间vc6uscn91#
除此之外,您的本机查询是错误的,因为没有
tickerr_users table
-你的别名叫做tickerr_users1
以及tickerr_users2
,一个合适的解决方案是使用内置的查询生成器像下面这样的方法应该能奏效