Php 根据codeigniter中的索引获得的结果
下面是我的代码,用于显示获得的结果计数 我的控制器看起来像这样Php 根据codeigniter中的索引获得的结果,php,arrays,codeigniter,Php,Arrays,Codeigniter,下面是我的代码,用于显示获得的结果计数 我的控制器看起来像这样 $data['present'][]= $this->attendance_model->present_report_by_empid($v_employee->user_id,$date); 我的模型看起来像这样 public function present_report_by_empid($user_id = null,$date = null) { $temp = explode("-",
$data['present'][]= $this->attendance_model->present_report_by_empid($v_employee->user_id,$date);
我的模型看起来像这样
public function present_report_by_empid($user_id = null,$date = null)
{
$temp = explode("-",$date);
$query='tbl_attendance.date_in';
$this->db->where('tbl_attendance.attendance_status', 1);
$this->db->where('tbl_attendance.user_id', $user_id);
$this->db->where("YEAR(tbl_attendance.date_in)",$temp[0]);
$this->db->where("MONTH(tbl_attendance.date_in)",$temp[1]);
$result = $this->db->get('tbl_attendance')->result_array();
$count=count($result); //counts number of rows
return $count;
}
<?php foreach($present as $key1 => $row){?>
<?php echo $row;?>
<?php }?>
视图看起来像这样
public function present_report_by_empid($user_id = null,$date = null)
{
$temp = explode("-",$date);
$query='tbl_attendance.date_in';
$this->db->where('tbl_attendance.attendance_status', 1);
$this->db->where('tbl_attendance.user_id', $user_id);
$this->db->where("YEAR(tbl_attendance.date_in)",$temp[0]);
$this->db->where("MONTH(tbl_attendance.date_in)",$temp[1]);
$result = $this->db->get('tbl_attendance')->result_array();
$count=count($result); //counts number of rows
return $count;
}
<?php foreach($present as $key1 => $row){?>
<?php echo $row;?>
<?php }?>
当我使用代码时,得到的结果如下
但我希望我的结果是这样的
看起来您正在首先使用每个人的数据构建
$data['present']
数组,因此您可能希望这样做:-
$data['present'][$v\u employee->user\u id]=$this->attention\u model->present\u report\u by\u empid($v\u employee->user\u id,$date)代码>
在视图中,您将传入$user\u id
,然后只需回显正确用户的数据:-
看起来您正在首先使用每个人的数据构建$data['present']
数组,因此您可能希望这样做:-
$data['present'][$v\u employee->user\u id]=$this->attention\u model->present\u report\u by\u empid($v\u employee->user\u id,$date)代码>
在视图中,您将传入$user\u id
,然后只需回显正确用户的数据:-
试试这个:
$data['present'][$v_employee->user_id]= $this->attendance_model->present_report_by_empid($v_employee->user_id,$date);
$empl = array(
// empl_id => name,
1 => 'administrator',
2 => 'siraj',
3 => 'faizal',
4 => 'nesru',
)
foreach($empl as $key1 => $row){
echo $row;
if (!isset($data['present'][$key1])) {
echo ' '.$data['present'][$key1];
} else {
echo ' - ';
}
}
试试这个:
$data['present'][$v_employee->user_id]= $this->attendance_model->present_report_by_empid($v_employee->user_id,$date);
$empl = array(
// empl_id => name,
1 => 'administrator',
2 => 'siraj',
3 => 'faizal',
4 => 'nesru',
)
foreach($empl as $key1 => $row){
echo $row;
if (!isset($data['present'][$key1])) {
echo ' '.$data['present'][$key1];
} else {
echo ' - ';
}
}
你的问题不清楚,请详细说明。您还应该使用$this->db->get('tbl_attention')->num_rows()
获取行数此代码返回的行数实际上与num_rows()
返回的行数相同,但您使用的是long方法来执行相同的操作。k关于这个问题,我们可以讨论获取结果吗?我们的问题不清楚,请详细说明。您还应该使用$this->db->get('tbl_attention')->num_rows()
获取行数此代码返回的行数与num\u rows()
实际返回的行数相同,但您使用的是long方法来执行相同的操作。k离开这里,我们可以讨论获取结果吗?出现如下消息:未定义变量:用户id您需要将用户id作为变量传递给视图。例如:-$data['user\u id']=$v\u employee->user\u id
这里有这样一条消息:未定义变量:user\u id您需要将user\u id作为变量传递给视图。例如:-$data['user\u id']=$v\u employee->user\u id