问题描述
我有一个侧边栏的类别。当我点击一个分类,它显示我位于该类别的工厂。
I have a sidebar with categories. when i click on one categorie it shows me the factories who are located in that category.
我使用在codeigniter中的连接。
I did this using joins in codeigniter.
现在我想显示一个类别中有多少工厂。例如:
Now i want to show how much factories are in a category. so for example:
Categories.
Cars (2)
Books (7)
Animals (45)
所以很简单就要显示有多少工厂有这个特定的类别。
So it simple has to show how much factories have that specific category.
我试图做一个简单的count_all_results但是我得到总数的工厂。
i tried to do a simple count_all_results but then i get the total count of factories. but i want them to count by the specific id of categories.
我的模型功能:
function categorieen_getall($segment3)
{
$this->db->where('categorieen.idcategorieen', $segment3);
$this->db->select('*');
$this->db->from('bedrijfcategorieen');
$this->db->join('categorieen', 'categorieen.idcategorieen = bedrijfcategorieen.idcategorieen');
$this->db->join('bedrijven', 'bedrijven.idbedrijven = bedrijfcategorieen.idbedrijven');
$query = $this->db->get();
$result = $query->result();
/*
echo '<pre>';
print_r($result);
*/
return $result;
}
我的控制器功能:
function get_All()
{
$data['cat'] = $this->categorieen_model->categorieen_getall($segment3);
$this->load->view('views/sidebar', $data);
}
我的观点:
<div id="sidebar">
<?php
echo '<h3>Categorieën</h3>';
echo ($this->db->count_all_results('categorieen'));
?>
<hr>
<br/>
<?php
echo '<ul>';
if(isset($cat) && is_array($cat)){
foreach($links as $k => $value){
echo '<li>';
echo '<br>';
echo '<a href="'.base_url().'home/categorie/'.$value->idcategorieen.' ">' .$value->Categorie. '</a>';
echo '</li>';
}
}
echo '<ul>';
/*
if(isset($cat ) && is_array($cat )){
foreach($cat as $key => $row){
echo "Categorie:"; echo $row->Categorie;
echo "<br />";
echo $row->idcategorieen;
echo "<br />";
echo $row->Bedrijfsnaam;
}
}
*/
?>
</div>
我的数据库方案:
Factories
--------
idfactories
factoryname
adress
email
...
Categories
----------
idcategories
Category
Factorycategories
-----------------
idfactorycategories
idcategories
idfactories
推荐答案
我问了另一个问题。有同样的问题,我解决了。
I asked another question. with the same problem and i solved it.
看看我自己的答案与我有解决方案!
Look at my own answer with the solution i got!
感谢帮助我的人:)
这篇关于在侧栏中显示类别后面的工厂数量。代码指示符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!