【问题标题】:strtotime() expects parameter 1 to be string, array givenstrtotime() 期望参数 1 是字符串,给定数组
【发布时间】:2015-12-13 17:35:46
【问题描述】:

查看result_array时出错,请帮我查看此视图​​。

型号:

public function raw_attendance_Status() {
        $this->db->distinct();
        $this->db->select('attnDate');
        $this->db->from('tbl_attendance');
        $this->db->order_by('attnDate');
        $query = $this->db->get();
        return $query->result_array();
    }

控制器:

public function rawAttendance(){
        $data['Dates'] = $this->AttendanceModel->raw_attendance_Status();
        $this->load->view('attendance/rawAttendance', $data);
    }

查看:

foreach ($Dates as $k=>$v) {
        $dates[$k] = date('d-M-Y', strtotime($v));
    }
    $heads = "<table border='1'>\n";
    $heads .= "<tr><th>TraineeID</th><th>" . join('</th><th>', $dates) . "</th></tr>\n";
$tdata .= "</table\n";

$dates 变量输出: array(13) { [0]=&gt; array(1) { ["attnDate"]=&gt; string(10) "2015-11-25" } [1]=&gt; array(1) { ["attnDate"]=&gt; string(10) "2015-11-29" } [2]=&gt; array(1) { ["attnDate"]=&gt; string(10) "2015-11-30" } [3]=&gt; array(1) { ["attnDate"]=&gt; string(10) "2015-12-01" } [4]=&gt; array(1) { ["attnDate"]=&gt; string(10) "2015-12-02" } [5]=&gt; array(1) { ["attnDate"]=&gt; string(10) "2015-12-03" } [6]=&gt; array(1) { ["attnDate"]=&gt; string(10) "2015-12-05" } [7]=&gt; array(1) { ["attnDate"]=&gt; string(10) "2015-12-06" } [8]=&gt; array(1) { ["attnDate"]=&gt; string(10) "2015-12-07" } [9]=&gt; array(1) { ["attnDate"]=&gt; string(10) "2015-12-08" } [10]=&gt; array(1) { ["attnDate"]=&gt; string(10) "2015-12-09" } [11]=&gt; array(1) { ["attnDate"]=&gt; string(10) "2015-12-10" } [12]=&gt; array(1) { ["attnDate"]=&gt; string(10) "2015-12-12" } }

【问题讨论】:

  • 请检查我的回答。

标签: php codeigniter


【解决方案1】:

由于您的结果以多维数组的形式返回,因此使用:

$dates[] = date('d-M-Y', strtotime($v['attnDate']));

代替:

$dates[] = date('d-M-Y', strtotime($v));

【讨论】:

  • 未定义索引:date_column_name.
  • 使用:print_r($v);它将显示所有 cloumns 因为 $v 在数组中
  • 如果答案正确,请不要忘记投票
【解决方案2】:

您确定 attnDate 字段是日期类型吗?
因为这个错误

strtotime() 期望参数 1 是字符串,给定数组

当你使用其他类型或你的值为空时显示
在视图中打印 $Dates 并显示结果

【讨论】:

  • 我添加了输出,请看一下。
  • 使用 'attnDate' 而不是 'date_column_name'
猜你喜欢
  • 2021-02-06
  • 2020-10-01
  • 1970-01-01
  • 2021-01-13
  • 2015-07-12
  • 2016-04-30
  • 2014-12-09
  • 2017-03-22
相关资源
最近更新 更多