我在CodeIgniter视图中有一个带有Read More Option的引导卡。在单击按钮时,url显示所选的卡片ID,但只从数据库中获取第一行。不确定,我哪里做错了。
控制器代码从这里开始
public function getDetails()
{
$query = $this->db->query("SELECT swo_brief_intro, swo_image_heading FROM services_offered");
$row = $query->row();
if (isset($row))
{
echo $row->swo_image_heading;
echo $row->swo_brief_intro;
}
}
View代码从这里开始
<div class="row clearfix">
<?php
$query = $this->db->query("SELECT * FROM services_offered LIMIT 15");
foreach ($query->result() as $row) {
echo "<div class='col-lg-4 bottommargin-sm'>";
echo "<div class='feature-box media-box fbox-bg'>";
echo "<div class='fbox-media'>";
echo "<a href='#'><img src='$row->swo_images' alt='Featured Box Image' style='height:250px; width:450px;'></a></div>";
echo "<div class='fbox-content fbox-content-lg'>";
$string = $row->swo_brief_intro;
$string = word_limiter($string, 15);
echo "<h3 class='nott ls0 font-weight-semibold'>$row->swo_image_heading<span class='subtitle font-secondary font-weight-light ls0'>$string</span></h3>";
echo "<a href='Fetch/getDetails/{$row->id}' class='button-link border-0 color btn-edit'>Read More</a>";
echo "</div>";
echo "</div>";
echo "</div>";
}
?>
请协助。由于
a)您忘记在函数中添加Id参数。
b)以及忘记基于此更改查询。
public function getDetails($id)
{
$row = $this
-> db
-> select('swo_brief_intro, swo_image_heading')
-> where('<put here id column name>', $id)
-> limit(1)
-> get('services_offered')
-> row();
if (isset($row))
{
echo $row->swo_image_heading;
echo $row->swo_brief_intro;
}
}