我在控制器中的变量"antrian_seminggu"中收到错误非法字符串偏移量。 你能告诉我问题出在哪里吗? 谢谢之前。
我的控制器
public function antrian_seminggu()
{
$tahun = date('Y');
$bulan = date('m');
$tanggal = date('d');
$format = $tahun.'-'.$bulan.'-'.$tanggal;
$seminggu = abs(6*86400);
$awal = strtotime($format);
$akhir = strtotime($format)+$seminggu;
for($i=$awal; $i <=$akhir;$i+=86400)
{
$data=date('Y-m-d', $i);
$this->db->select('p.nama as nama_pasien,p.alamat as alamat_pasien, pen.id_pendaftaran as id,pen.tanggal_periksa as tgl, l.nama_layanan as layanan_pasien, pen.nama_detail_layanan as detail_layanan, pen.biaya as biaya_total, d.nama as nama_dokter,pen.status as stat, pen.no_antrian as antrian');
$this->db->from('pasien p, pendaftaran pen, layanan l, dokter d');
$this->db->where('p.NIK=pen.NIK');
$this->db->where('pen.id_layanan=l.id_layanan');
$this->db->where('l.id_dokter=d.id_dokter');
$this->db->where('pen.tanggal_periksa',$data);
$this->db->order_by('pen.tanggal_periksa','ASC');
$this->db->order_by('d.nama','ASC');
$this->db->order_by('pen.no_antrian','ASC');
$query=$this->db->get();
$data['antrian_seminggu']=$query;
$this->load->view('admin/antrian_data_seminggu',$data);
}
}
我的观点
<?php
$no=0;
foreach ($antrian_seminggu->result() as $dat)
{
?>
illegal string offset warning
在未正确设置array
时出现。这可能是由于多种原因造成的。我正在下面编写经过更正的代码,必要时会提到注释。看看它是否对你有帮助。
控制器
public function antrian_seminggu()
{
$tahun = date('Y');
$bulan = date('m');
$tanggal = date('d');
$format = $tahun.'-'.$bulan.'-'.$tanggal;
$seminggu = abs(6*86400);
$awal = strtotime($format);
$akhir = strtotime($format)+$seminggu;
for($i=$awal; $i <=$akhir;$i+=86400)
{
$date = date('Y-m-d', $i);
$this->db->select('p.nama as nama_pasien,p.alamat as alamat_pasien, pen.id_pendaftaran as id,pen.tanggal_periksa as tgl, l.nama_layanan as layanan_pasien, pen.nama_detail_layanan as detail_layanan, pen.biaya as biaya_total, d.nama as nama_dokter,pen.status as stat, pen.no_antrian as antrian');
$this->db->from('pasien p, pendaftaran pen, layanan l, dokter d');
$this->db->where('p.NIK=pen.NIK');
$this->db->where('pen.id_layanan=l.id_layanan');
$this->db->where('l.id_dokter=d.id_dokter');
$this->db->where('pen.tanggal_periksa',$date);
$this->db->order_by('pen.tanggal_periksa','ASC');
$this->db->order_by('d.nama','ASC');
$this->db->order_by('pen.no_antrian','ASC');
$query=$this->db->get()->result(); // complete the query here
$data['antrian_seminggu'][] = $query; // you probably want an array here otherwise the previous value will be overwritten by current value
}
$this->load->view('admin/antrian_data_seminggu', $data); // you'd want to load the view only once, so it should be outside the loop.
}
视图
<?php
$no=0;
foreach ($antrian_seminggu as $dat)
{
var_dump($dat); echo '<br>'; // returns all the data
}
?>