php - MySQL结果提供重复项,如何停止

标签 php mysql duplicates

通过 MySQL 请求,我收到了 id 的重复项,并且想知道是否有办法防止这种情况发生。

哪里

饮料:1 食物:2 熟食店:3 货架:4

子导航 1 显示 11 两次。

输出示例 example output

虽然请求准确返回,但我只需要 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/

相关文章:

php - 使用API​​ v3删除Youtube中的播放列表项

php - 在 IF 语句中更新数据库

java - 每次切换 Activity 时 dubbel json 输出

php - 使用 "toxi"模式的 mysql 标签查询

php - PostGIS 中的聚类点

mysql - MySQL 中的存储函数不喜欢用户提供的日期?

php - laravel 查询中具有 where 条件的数组值

c# - 从集合中删除重复的 byte[]

algorithm - 查找重复项的第三种方法

php - mysqli::query() 期望参数 2 很长,给出字符串