如何显示类别的项目?

时间:2017-04-06 08:33:33

标签: php mysql

我需要显示每个类别的项目。我使用smarty模板。所以我得到这样的类别:

{foreach $news as $article}
    <div class="panel panel-info">
        <div class="panel-heading">{$article["name"]}</div>
        <div class="panel-body">
            "Here I need to display Items that have FOREIGN KEY 'category_id'" 
        </div>
    </div>
{/foreach}

我是否应该获取类别的ID以及如何显示它? It's a category list with ID

我想改进我的问题 - 这里有一些指向我Controller的链接。我试图建立更多的链接,但我不能低声望。请试着看看我做错了什么?

1 个答案:

答案 0 :(得分:0)

<?php
$lists = '';
$query = "your query example" - mysqli_query($conn,"select * from article"); 
if(!$mysqli_num_rows<0){
while($row = mysqli_fetch_array($query,MYSQLI_ASSOC)){
    $id = $row["category_id"];
    $name = $row["name"];

    $lists .= '<div class="panel panel-info">
        <div class="panel-heading">'.$name.'</div>
        <div class="panel-body">
            "Here I need to display Items that have FOREIGN KEY '.$id.'" 
        </div>
    </div>';
}

    echo $lists;
}


?>