0
$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;
        }
    }
4

2 回答 2

3

空对象不为假。

至于您的评论,请确保total_cost_for_A 并且B实际上正在返回一些东西。并确保他们false以失败告终。这是您的条件评估为真的唯一方法。

您正在使用严格的相等比较,因此除非您返回,否则它们永远不会等于 false false

if(($total_cost_for_A == FALSE) && ($total_cost_for_B == FALSE))

以上应该有效,因为空数组是错误的。

于 2012-09-07T19:09:18.483 回答
0

看来您的比较需要使用 $total_cost_代表_A 和 $total_cost_代表_B

您的变量名中缺少“for”。

于 2012-09-07T18:35:09.593 回答