在我没有得到任何回复之前我问了这个问题,如果有帮助我决定重新发布。我希望通过重新发布我没有做错任何事情?
$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 :(得分: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”你可以直接给出它,如果它在你的表中有条件的地方,也试着避免模型中的函数和变量分配的相同名称。尝试改变为不同。否则你的代码看起来不错
答案 1 :(得分: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()
相同