从 codeigniter 中的返回数组中获取单独的结果
get separate result from returning array in codeigniter
I would like to tell you that I am stuck in the simple logic.I know it is so simple but I need a help this time.
I have an array <strong>$allCategories</strong> that returns data from db table. ( select * from tablename)
Structure is like this:
============================================= =====================
ID 类别名称说明父类别
================================================ ================
1 ABCD 2
2 JKL 网络服务器 0
3. WXYZ 绝杀本身 1
I want to show Category name instead of digits.Actually The digits are the Id of the Cateogry name.
Like JKL comes instead of 2 and ABCD instead of 1.
<?php $i =1;
foreach($allCategories as $ab){
?>
<tr class="pointer">
<td class=" "><?php echo $i ?></td>
<td class=" "><?php echo $ab['category_name'] ?></td>
<td class=" "><?php echo $ab['category_description']; ?></td>
<td class=" ">
<?php
$parent_category = $ab['parent_category'];
return $this->db->select('category_name')
->from('categories')
->where('id', $parent_category)
->get()
->row();
//echo $ab['parent_category']
?>
</td>
</tr>
<?php
$i++;
}
?>
如果您想了解有关我的问题的任何信息或疑问。问我
提前致谢:)
这里不要使用"return"。像这样更改它:
echo $this->db->select('category_name')
->from('categories')
->where('id', $parent_category)
->get()
->row()["category_name"];
I would like to tell you that I am stuck in the simple logic.I know it is so simple but I need a help this time.
I have an array <strong>$allCategories</strong> that returns data from db table. ( select * from tablename)
Structure is like this:
============================================= =====================
ID 类别名称说明父类别
================================================ ================
1 ABCD 2
2 JKL 网络服务器 0
3. WXYZ 绝杀本身 1
I want to show Category name instead of digits.Actually The digits are the Id of the Cateogry name.
Like JKL comes instead of 2 and ABCD instead of 1.
<?php $i =1;
foreach($allCategories as $ab){
?>
<tr class="pointer">
<td class=" "><?php echo $i ?></td>
<td class=" "><?php echo $ab['category_name'] ?></td>
<td class=" "><?php echo $ab['category_description']; ?></td>
<td class=" ">
<?php
$parent_category = $ab['parent_category'];
return $this->db->select('category_name')
->from('categories')
->where('id', $parent_category)
->get()
->row();
//echo $ab['parent_category']
?>
</td>
</tr>
<?php
$i++;
}
?>
如果您想了解有关我的问题的任何信息或疑问。问我 提前致谢:)
这里不要使用"return"。像这样更改它:
echo $this->db->select('category_name')
->from('categories')
->where('id', $parent_category)
->get()
->row()["category_name"];