0

我在连接此查询时遇到问题:

$sql.=' WHERE ticket.dept_id IN('.implode(',',$thisuser->getDepts()).') OR ticket.staff_id='.db_input($thisuser->getId());

有了这个:

AND ticket.brand_id IN('.implode(',',$thisuser->getBrands())

我怎样才能做到这一点?

4

1 回答 1

1

您可以将字符串连接到同一行:

$sql.=' WHERE ticket.dept_id IN('.implode(',',$thisuser->getDepts()).') OR ticket.staff_id='.db_input($thisuser->getId()) . ' AND ticket.brand_id IN('.implode(',',$thisuser->getBrands()) . ')';

或者您可以在第二行执行此操作:

$sql.=' WHERE ticket.dept_id IN('.implode(',',$thisuser->getDepts()).') OR ticket.staff_id='.db_input($thisuser->getId());
$sql.=' AND ticket.brand_id IN('.implode(',',$thisuser->getBrands()) . ')';

但是,由于您的原始WHERE子句包含一个OR,因此您必须确保保持逻辑完整。AND我建议在连接附加子句之前将前两个条件包含在一组括号中:

$sql.=' WHERE (ticket.dept_id IN('.implode(',',$thisuser->getDepts()).') OR ticket.staff_id='.db_input($thisuser->getId()) . ')';
$sql.=' AND ticket.brand_id IN('.implode(',',$thisuser->getBrands()) . ')';
于 2012-12-04T17:52:47.363 回答