此查询可以在phpmyadmin上顺利运行。但是在我的项目中,它不是在查询。
$sql = 'SELECT p.est_id,p.sec_plan_number,p.plot_plan_number,
(select policyno from tbl_plot_statusd where est_id=p.est_id
and sec_plan_number=p.sec_plan_number and plot_plan_number=p.plot_plan_number
and op_id=ps.op_id) as policyno, (select nic from tbl_plot_statusd
where est_id=p.est_id and sec_plan_number=p.sec_plan_number
and plot_plan_number=p.plot_plan_number and op_id=ps.op_id) as nic
FROM `tbl_plot` p left join tbl_plot_status ps on p.est_id=ps.est_id
and p.sec_plan_number = ps.sec_plan_number and p.plot_plan_number=ps.plot_plan_number
where ps.status_type_code=2 and ps.is_last_status=1 and p.isactive=1
order by ps.est_id,ps.sec_plan_number,abs(ps.plot_plan_number)';
foreach ($db->query($sql) as $d)
答案 0 :(得分:0)
尝试
$query = $db->query($sql);
foreach ($query->fetchAll() as $d)
{
}