隐藏php / myqli中的重复行?

时间:2018-02-26 16:34:58

标签: php mysql

我希望你好好,我在学校项目中工作,管理其中的所有影响,我得到一个问题,因为图像描述它duplicate each row我的目的是只显示一个'MATIERE'与所有'NOTE_DEVOIR' (表中的devoir),但我得到的每个重复与我们在这个'devoir'中重复。

注意:教师用'MODULE_DEVOIR'添加'NOTE_DEVOIR',这意味着每次使用'NOTE_DEVOIR'时,'MODULE'都是重复的  database

我需要隐藏不要删除

PHP:

echo"<br><button class='btn btn-info cursor' name='butAf'>Afficher</button>";



if(isset($_POST['butAf']))
{        

    /*ID_CLASS and ID_ANNEE just to filter the class and the year of study*/
$query5 = "select * from devoir inner join prof_an_cls on  prof_an_cls.ID_PROF_AN_CLS = devoir.ID_PROF_AN_CLS where CIN_ELEVE = '$cinE' and ID_ANNEE=$ID_ANNEE and  ID_CLASS = $ID_CLASS";
$result5 = mysqli_query($con,$query5);
if(mysqli_num_rows($result5)>0)
{
    echo"<table class='table table-bordered table-striped table-hover table-info'><tr>
    <th>MATIERE</th>
    <th>devoir1</th>
    <th>devoir2</th>
    <th>devoir3</th>
    <th>devoir4</th>
    <th>devoir5</th>

    </tr>
    ";
    while($rows = mysqli_fetch_assoc($result5))
    {/*i guess this loop its the reason of duplicating */
       $moduleD = $rows['MODULE_DEVOIR'];

    $queryDEV = "select * from devoir inner join eleve on devoir.CIN_ELEVE = eleve.CIN_ELEVE where eleve.CIN_ELEVE = '$cinE' and MODULE_DEVOIR = '$moduleD' order by MODULE_DEVOIR";

    $resultDEV = mysqli_query($con,$queryDEV);
        echo"<tr><td>$moduleD</td>";     

           while($rows = mysqli_fetch_assoc($resultDEV))/*loop2*/
            {
                $noteDEV = $rows['NOTE_DEVOIR'];

                  echo"<td>$noteDEV</td>";


              }


        echo"</tr>";
    }



    echo"</table>";
}
}

2 个答案:

答案 0 :(得分:3)

你要么用

DISTINCT

SELECT DISTINCT column . . . WHERE . . .

GROUP BY

SELECT column . . . WHERE . . . GROUP BY column

您可以查看此answer

中的差异

答案 1 :(得分:0)

$queryDEV上,只需添加GROUP BY devoir.matiere(我假设列名称为'matiere'),您就应该获得非重复的行