简体   繁体   English

PHP / Codeigniter逻辑运算符

[英]PHP/Codeigniter Logical Operator

$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);

The variables $total_cost_for_A and $total_cost_for_B hold the returned value from a mysql summation queries in the model. 变量$ total_cost_for_A和$ total_cost_for_B保存模型中mysql求和查询的返回值。 The queries return false if no record was found. 如果未找到任何记录,则查询返回false。 Now, I'm trying to perform this operation. 现在,我正在尝试执行此操作。

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);
}

This test always fail and execute the else statement instead, which is not what. 该测试总是失败,而是执行else语句,而事实并非如此。 Any assistance will be appreciated. 任何帮助将不胜感激。 Thanks 谢谢

Here are the functions 这是功能

    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;
        }
    }

Empty objects are not false. 空对象不是假的。

As for your comment, please make sure that total_cost_for_A and B are actually returning something. 关于您的评论,请确保total_cost_for_AB实际上返回了一些东西。 And make sure that they are returning false on failure. 并确保它们在失败时返回false That is the only way your conditional will evaluate to true. 这是您的条件评估为true的唯一方法。

You are using strict equality comparison so they will never equal false unless you return false ! 您正在使用严格的相等比较,因此除非返回false否则它们永远不会等于false

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

The above should work because empty arrays are false. 上面的应该起作用,因为空数组为false。

It seems your comparisons need to use $total_cost_ for _A and $total_cost_ for _B 似乎您的比较需要 _A使用$ total_cost_ _B使用$ total_cost_

you are missing "for" from your variable names. 您缺少变量名称中的“ for”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM