- 此问题在此处已有答案**:
CodeIgniter get_where(4个答案)
昨天关门了。
因此,我尝试设置一个条件,如果$lowongan->status == 'active'
,它将显示状态为active
的数据行,但我得到了错误消息:Attempt to read property "status" on array
我如何解决这个问题??
模型:
public function show_lowongan(){
return $this->db->get('lowongan');
}
主计长:
public function lowongan()
{
$data['lowongan'] = $this->m_lowongan->show_lowongan()->result();
$this->load->view('lowongan', $data);
}
该视图:
<div class="row">
<?php if($lowongan->status == "draft"){?>
<?php
$no = 1;
foreach($lowongan as $lowong){
?>
<div class="card" style="width: 18rem;">
<div class="card-body">
<h5><?php echo $lowong->title?></h5>
<p><?php echo $lowong->lokasi?></p>
<p><?php echo $lowong->created_at?></p>
<p><?php echo $lowong->level_pekerja?></p>
<p><?php echo $lowong->pengalaman_kerja?></p>
<p><?php echo $lowong->pendidikan?></p>
<p><?php echo $lowong->alamat?></p>
<p><?php echo $lowong->no_wa?></p>
<p><?php echo $lowong->no_telp?></p>
<p><?php echo $lowong->min_gaji?></p>
<p><?php echo $lowong->max_gaji?></p>
<p><?php echo $lowong->job_desc?></p>
<button><a href="<?php echo base_url('lowongan/detail/'.$lowong->id)?>">Detail Lowongan</a></button>
<button><a href="<?php echo base_url('lowongan/edit/'.$lowong->id)?>">Edit Lowongan</a></button>
<button><a href="<?php echo base_url('lowongan/delete/'.$lowong->id)?>">Hapus Lowongan</a></button>
</div>
</div>
<?php }?>
<?php }else{?>
Sorry No Job Posting
<?php }?>
</div>
1条答案
按热度按时间r55awzrz1#
需要两个条件
1.检查作业总数
if(count($lowongan) > 0)
或if (!$lowongan)
1.检查每个$lowong.
if($lowong->status == "draft")
的状态您已经将
if
条件置于for
循环之上,它应该位于for
循环之下,以便您可以访问单个$lowong
并进一步访问其$lowong->status
,如下所示: