Php 找不到记录,而不是为foreach()-CodeIgniter提供的无效参数
我在CodeIgniterController中有以下代码。当启用从模型检索数据时,它返回为foreach()提供的Php 找不到记录,而不是为foreach()-CodeIgniter提供的无效参数,php,codeigniter,Php,Codeigniter,我在CodeIgniterController中有以下代码。当启用从模型检索数据时,它返回为foreach()提供的无效参数。我想显示“未找到记录”而不是无效参数。。错误 这是我的全部代码 控制器 function registered_customers_bod(){ // get the data and pass to records Variable if($query = $this->mod_reports->registered_cus
无效参数。我想显示“未找到记录”而不是无效参数。。错误
这是我的全部代码
控制器
function registered_customers_bod(){
// get the data and pass to records Variable
if($query = $this->mod_reports->registered_customers_bod())
{
$data['records'] = $query ;
}else{
$data['records'] = 'No records found';
}
$data['report_name'] = $this->input->post('report_name');
// load the view passing data Variable
$this->load->view('admin/reports/user_reports_bod.html',$data);
}
查看-用户报告\u bod
<?php if (isset($records)) : $i = 1; $delivered_qty_total = 0; foreach ($records as $row) : ?>
<tr>
<td><?php echo $i++; ?></td>
<td><?php echo $row->cus_id; ?></td>
<td><?php echo $row->cus_name; ?></td>
<td><?php echo $row->cus_email; ?></td>
<td><?php echo $row->cus_phone; ?></td>
<td><?php echo $row->cus_mobile; ?></td>
<td><?php echo $row->cus_addr_city; ?></td>
<td><?php echo $row->user_status; ?></td>
<td><?php echo gmdate("Y/m/d", $row->user_timestamp); ?></td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
型号
function registered_customers_bod(){
$to = new DateTime($this->input->post('to'));
$from = new DateTime($this->input->post('from'));
$this->db->select(array(
'tbl_customer_registration.cus_id',
'tbl_customer_registration.cus_name',
'tbl_customer_registration.cus_email',
'tbl_customer_registration.cus_phone',
'tbl_customer_registration.cus_mobile',
'tbl_customer_registration.cus_addr_no',
'tbl_customer_registration.cus_addr_street',
'tbl_customer_registration.cus_addr_city',
'tbl_user_registration.user_status',
'tbl_user_registration.user_reason_status',
'tbl_user_registration.user_timestamp',
));
$this->db->from('tbl_customer_registration');
$this->db->join('tbl_user_registration', 'tbl_user_registration.user_id=tbl_customer_registration.user_id');
$this->db->group_by("tbl_customer_registration.cus_id"); //view single record that contain two contact numbers
$this->db->where('user_timestamp >=',$to->getTimestamp());
$this->db->where('user_timestamp <=',$from->getTimestamp());
$query = $this->db->get();
return $query->result();
}
功能注册\客户\董事会(){
$to=newdatetime($this->input->post('to');
$from=newdatetime($this->input->post('from'));
$this->db->select(数组)(
‘tbl_客户注册。客户id’,
“待定客户注册。客户名称”,
“tbl_客户注册。客户电子邮件”,
‘tbl_客户注册。客户电话’,
“tbl_客户注册。客户移动”,
“待定客户注册。客户地址编号”,
“待客户注册。客户地址街”,
“tbl_客户注册。客户地址城市”,
“tbl_用户注册。用户状态”,
“tbl\u用户注册。用户原因\u状态”,
“tbl_用户注册。用户时间戳”,
));
$this->db->from('tbl_客户注册');
$this->db->join('tbl\u user\u registration','tbl\u user\u registration.user\u id=tbl\u customer\u registration.user\u id');
$this->db->group_by(“tbl_customer_registration.cus_id”);//查看包含两个联系人号码的单个记录
$this->db->where('user\u timestamp>=',$to->getTimestamp());
$this->db->where('user\u时间戳
错误背后的原因是当从数据库中找不到记录时,$data['records']
是一个字符串,它肯定是foreach()的无效参数。
使用empty($records)
把其他事情放在眼里
编辑
$arr = (array)$records;
if(!empty($arr)){
$i = 1;
$delivered_qty_total = 0;
foreach($records as $row) { ?>
<tr>
<td><?php echo $i++; ?></td>
<td><?php echo $row->cus_id; ?></td>
<td><?php echo $row->cus_name; ?></td>
<td><?php echo $row->cus_email; ?></td>
<td><?php echo $row->cus_phone; ?></td>
<td><?php echo $row->cus_mobile; ?></td>
<td><?php echo $row->cus_addr_city; ?></td>
<td><?php echo $row->user_status; ?></td>
<td><?php echo gmdate("Y/m/d", $row->user_timestamp); ?></td>
</tr>
<?php } ?>
}
else { echo "No records found";}
$arr=(数组)$records;
如果(!空($arr)){
$i=1;
$delivered\u quantity\u total=0;
foreach($记录为$行){?>
}
else{echo“未找到任何记录”;}
也发布模型代码,当$data['records']='No records found';
您肯定会得到为foreach()提供的无效参数。@karanthakkar我更新了编码。请告诉我需要如何在此处添加其他内容谢谢我应用了它,但仍然没有显示No records found消息:(那么显示了什么?有错误吗?var_dump($records)
在查看中如果(!empty($records))
之前检查if(!empty($records))
我得到了它,并更新了答案,谢谢。在查看中编辑$arr=(array)$records;如果(!empty($arr))
$arr = (array)$records;
if(!empty($arr)){
$i = 1;
$delivered_qty_total = 0;
foreach($records as $row) { ?>
<tr>
<td><?php echo $i++; ?></td>
<td><?php echo $row->cus_id; ?></td>
<td><?php echo $row->cus_name; ?></td>
<td><?php echo $row->cus_email; ?></td>
<td><?php echo $row->cus_phone; ?></td>
<td><?php echo $row->cus_mobile; ?></td>
<td><?php echo $row->cus_addr_city; ?></td>
<td><?php echo $row->user_status; ?></td>
<td><?php echo gmdate("Y/m/d", $row->user_timestamp); ?></td>
</tr>
<?php } ?>
}
else { echo "No records found";}