通过 MySQL 请求,我收到了 id
的重复项,并且想知道是否有办法防止这种情况发生。
哪里
饮料:1
食物:2
熟食店:3
货架:4
子导航 1 显示 11
两次。
输出示例
虽然请求准确返回,但我只需要 id
返回一次。有没有办法实现这个目标?
MySQL
<?
$sql7x = " SELECT * FROM items_section_list ORDER BY item_sec_id ASC ";
$result7x = mysql_query($sql7x);
while ($row7x = mysql_fetch_array($result7x)) {
$item_sec_id = $row7x['item_sec_id'];
$section_name = $row7x['section_name'];
?>
<div id=''>
subnav: <? echo $item_sec_id; ?> ::
<?
$sql8x = " SELECT * FROM item_groups
WHERE section_id='$item_sec_id'
";
$result8x = mysql_query($sql8x);
while ($row8x = mysql_fetch_array($result8x)) {
echo $item_sub_sec_id = $row8x['item_sub_sec_id'];
echo ", ";
}
?>
最佳答案
尝试使用
SELECT distinct(id) from...
关于php - MySQL结果提供重复项,如何停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22917542/