-3

我在没有得到更多回复之前问了这个问题,如果这有帮助,我决定重新发布它。我希望我通过重新发布没有做错什么?

$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

0

尝试像这样改变

 $select_amount_paid = 'SELECT SUM(total_amount) total_amount FROM graphics_booking AS bk
        WHERE date = '.$date;//i assume that date is an colum from graphics_booking

你对“bk.date”有误,如果它在你的表中,你可以直接给出 where 条件,并尽量避免模型中的函数和分配的变量的名称相同。尝试更改为不同的。否则你的代码看起来不错

于 2012-09-08T04:11:28.770 回答
0

不,当你返回你不能返回整个,你需要返回一行

所以你需要在你的模型中做:

 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->row();     // you missed out here
        }
        else
        {
            return FALSE;
        }
    }

与 total_cost_for_B() 相同

于 2012-09-08T11:19:52.273 回答