我创建了一个代码来显示记录中项目的类别。
如果第1项是电话,则代码显示电话。但问题是,当同一类别有两个以上的代码时,代码会显示同一类别的两倍或两倍以上
https://i.imgur.com/zq5oahq.png
我的密码是
$select_parent = "SELECT ads_id, ads_title, category_id FROM public_ads WHERE ads_active = 1 AND ads_genre = 'Loja' AND ads_end = 0";
$parent_query = $con->query($select_parent);
if($parent_query->num_rows > 0) {
while($parents = $parent_query->fetch_assoc()) {
$select_categories = "SELECT category_id, category_title FROM public_categories WHERE category_id = '".$parents['category_id']."' ORDER BY category_id Limit 1";
$category_query = $con->query($select_categories);
while($options = $category_query->fetch_assoc()) {
echo '<li><a href="store?p='. $parents['category_id'] .'&article='. $options['category_title'] .'"><i class="fas fa-angle-right"></i> '. $options['category_title'] .'</a></li>';
}
}
}
2条答案
按热度按时间gj3fmq9x1#
尝试添加“distinct”。。。。如“选择不同的广告\u id….”
fnatzsnv2#
添加
GROUP BY category_id
在查询结束时(在WHERE
条款)。这会将结果限制为每个类别标识一行。