$total_cost_for_A = $this->admin_model->total_cost_for_A($branch, $department, $date);
$total_cost_for_B = $this->admin_model->total_cost_for_B($branch, $department, $date);
变量 $ total_cost_for_A和$ total_cost_for_B 保存模型中mysql求和查询的返回值。如果未找到记录,则查询返回false。现在,我正在尝试执行此操作。
if(($total_cost_for_A === FALSE) && ($total_cost_for_B === FALSE))
{
$data['no_record'] = 'No Record Found!';
$this->load->view('admin/bookings', $data);
}
else
{
$this->load->view('admin/summary', $data);
}
此测试总是失败并改为执行else语句,而不是什么。任何帮助将不胜感激。感谢
以下是功能
function total_cost_for_A($branch, $department, $date)
{
if($branch == 'Head Office' && $department == 'Summary')
{
$select_amount_paid = 'SELECT SUM(total_amount) total_amount FROM graphics_booking AS bk
WHERE bk.date = "'.$date.'"';
}
$result = $this->db->query($select_amount_paid);
if($result->num_rows() > 0)
{
return $result;
}
else
{
return FALSE;
}
}
function total_cost_for_B($branch, $department, $date)
{
if($branch == 'Head Office' && $department == 'Summary')
{
$total_LF_amount = 'SELECT SUM(total_amount) total_amount FROM large_format_print
WHERE date = "'.$date.'"';
}
$result = $this->db->query($total_LF_amount);
if($result->num_rows() > 0)
{
return $result;
}
else
{
return FALSE;
}
}
答案 0 :(得分:3)
空对象不是假的。
至于您的评论,请确保total_cost_for_A
并且B
实际上正在返回一些东西。并确保他们在失败时返回false
。这是条件评估为真的唯一方法。
您正在使用严格的相等比较,因此除非您返回false
!
if(($total_cost_for_A == FALSE) && ($total_cost_for_B == FALSE))
以上应该有效,因为空数组是假的。
答案 1 :(得分:0)
您的比较似乎需要使用$ total_cost_ 用于 _A和$ total_cost_ 用于 _B
你的变量名称中缺少“for”。