我的控制器
$data['judul'] = $this->pengumuman->getJudul($id_announcement);
我的模特
public function getJudul($id_announcement)
{
$this->db->select('mp.id_announcement, mp.title_announcement, mp.isi_pengumuman')
->from('tbl_mst_pengumuman mp')
->order_by('mp.id_announcement','DESC' ,$id_announcement)
->limit(3);
return $this->db->get()->row();
}
我的观点
<div class="portlet-body">
<div id="nt-example1-container">
<ul id="nt-example1" class="news">
<li>
<b><a href="<?= site_url('login/pengumuman/detail/'.@$judul->id_announcement); ?>" class="link_pengumuman"><?= $judul->title_announcement ?></a></b>
<?= $judul->isi_pengumuman ?>
<li><br>
<b><a href="<?= site_url('login/pengumuman/detail/'.@$judul->id_announcement); ?>" class="link_pengumuman"><?= $judul->title_announcement ?></a></b>
<?= $judul->isi_pengumuman ?>
</li><br>
<li>
<b><a href="<?= site_url('login/pengumuman/detail/'.@$judul->id_announcement); ?>" class="link_pengumuman"><?= $judul->title_announcement ?></a></b>
<?= $judul->isi_pengumuman ?>
</li> <br>
<li>
<b><a href="<?= site_url('login/pengumuman/detail/'.@$judul->id_announcement); ?>" class="link_pengumuman"><?= $judul->title_announcement ?></a></b>
<?= $judul->isi_pengumuman ?>
</li><br>
</div>
</div>
注意:在我试图展示的视图上。我不知道语法是否错误。
* sory我的英语太糟糕了
答案 0 :(得分:2)
<ul>
foreach($results as $value) {
echo "<li>";
// your code
echo "</li>";
}
</ul>
不要在每个li之间使用br,而是使用css。
答案 1 :(得分:0)
你正在使用$this->db->get()->row()
函数,它只返回1行,
你应该$this->db->get()->result()
另外,您在$id_announcement
内传递了order_by()
,这是错误的,我认为$id_announcement
将id
用id_announcement
过滤结果 public function getJudul($id_announcement)
{
$this->db->select('mp.id_announcement, mp.title_announcement, mp.isi_pengumuman')
->from('tbl_mst_pengumuman mp')
->where('mp.id_announcement', $id_announcement)
->limit(3)
->order_by('mp.id_announcement','DESC');
$query = $this->db->get();
return ($query->num_rows() > 0) ? $query->result() : false;
}
1}}
所以,你的模型函数应该如下所示
<?php if($judul){ ?>
<div class="portlet-body">
<div id="nt-example1-container">
<ul id="nt-example1" class="news">
<?php foreach($judul as $row){ ?>
<li>
<b><a href="<?= site_url('login/pengumuman/detail/'.$row->id_announcement); ?>" class="link_pengumuman"><?= $row->title_announcement; ?></a></b>
<?= $row->isi_pengumuman; ?>
</li>
<?php } ?>
</ul>
</div>
</div>
<?php }else{ echo 'no records found!'; } ?>
在视图文件中添加如下
<img src="cid:yourcontentid" />