codeigniter 代码点火器:尝试读取数组[duplicate]的属性"status"

jdzmm42g  于 2023-01-28  发布在  其他
关注(0)|答案(1)|浏览(119)
    • 此问题在此处已有答案**:

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>
r55awzrz

r55awzrz1#

需要两个条件
1.检查作业总数if(count($lowongan) > 0)if (!$lowongan)
1.检查每个$lowong.if($lowong->status == "draft")的状态
您已经将if条件置于for循环之上,它应该位于for循环之下,以便您可以访问单个$lowong并进一步访问其$lowong->status,如下所示:

<div class="row">
          <?php if(count($lowongan) > 0){?>
            <?php
              $no = 1;
              foreach($lowongan as $lowong){
            ?>
            <?php if($lowong->status == "draft"){?>
              <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>

相关问题