私は戻ってくるデータベースからデータを得ましたが、現時点ではすべてを1つの大きなリストに返します。カテゴリ別にSQLの結果を分割する
データには、カップルアイテムごとにカテゴリ名があります。カテゴリが割り当てられているアイテムのすべてのグループを分離したいと思います。
Example:
test1 (has category testing)
test2 (has category testing)
test3 (has category testing123)
これらの結果は、ただ一つの大きなリストに表示され、私は結果は以下のようになりたい:
testing:
test1
test2
testing123:
test3
私はこれをどのように行うのですか?
私のコードは今のように(関連する部分のみ):
while ($row_items = mysqli_fetch_assoc($res_items)) {
$checklist = '';
if ($row_items['checkpoints'] != '') {
$check = explode(',', $row_items['checkpoints']);
foreach($check as $list) {
$checklist .= '
<li class="cataloguslist">
<i style="color:#e88f41;" class="fa fa-check-square" aria-hidden="true">
</i> '.$list.'</li>';
}
}
echo '
<div class="col-lg-2 col-md-3 col-sm-6 col-xs-6 portf">
<a class="fancybox" href="../../catalogus/'.$row_items['afbeelding'].'">
<div class="gallery-item">
<div class="image">
<img src="../../catalogus_icons/'.$row_items['afbeelding'].'.jpg" alt="" style="border:1px solid #ccc;" class="img-responsive" />
</div>
<div class="bottom-info" style="min-height:200px;">
<div class="name">'.$row_items['naam'].'</div>
<ul style="margin-left:35px;margin-top:10px;">'.$checklist.'</ul>
<a href="contact.php">
<button class="contact_button buttoncontact btn-primary" style="border-radius:2px;">
Vraag offerte aan
<span class="icon-mail-alt"></span>
</button>
</a>
<div class="contactlink">
<a href="contact.php">Neem contact op</a>
</div>
</div>
</div>
</a>
</div>';
}
すべての結果はcat
同じid
とカテゴリ名とテーブル(producten_catsに接続し、データベース内cat
行を有しますその中のTableRow名でaswell:naam
;