如何在 Codeigniter 中获取特定的行数据
How to fetch specific row data in Codeigniter
我的 CodeIgniter 视图中有一张 bootstrap 卡片,其中包含阅读更多选项。单击按钮时,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;
}
}
视图代码从这里开始
<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;
}
}
我的 CodeIgniter 视图中有一张 bootstrap 卡片,其中包含阅读更多选项。单击按钮时,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;
}
}
视图代码从这里开始
<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;
}
}