0

My goal is to show just one 'matiere' with all 'devoir', but I get each 'matiere' duplicated for each 'devoir'. I need to hide these, not delete them.

enter image description here

A teacher can add a 'devoir' with their 'module devoir', which means the 'module' is duplicated each time with 'devoir'.

enter image description here

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>";
}
}
Graham
  • 7,431
  • 18
  • 59
  • 84
  • Don't use this style of query building - it is dangerous. See: [this discussion about sql injection](https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) – ventiseis Feb 25 '18 at 18:51
  • 3
    **WARNING**: When using `mysqli` you should be using [parameterized queries](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and [`bind_param`](http://php.net/manual/en/mysqli-stmt.bind-param.php) to add user data to your query. **DO NOT** use string interpolation or concatenation to accomplish this because you have created a severe [SQL injection bug](http://bobby-tables.com/). **NEVER** put `$_POST`, `$_GET` or **any** user data directly into a query, it can be very harmful if someone seeks to exploit your mistake. – tadman Feb 25 '18 at 19:00
  • 1
    Note: The object-oriented interface to `mysqli` is significantly less verbose, making code easier to read and audit, and is not easily confused with the obsolete `mysql_query` interface. Before you get too invested in the procedural style it’s worth switching over. Example: `$db = new mysqli(…)` and `$db->prepare("…")` The procedural interface is an artifact from the PHP 4 era when `mysqli` API was introduced and should not be used in new code. – tadman Feb 25 '18 at 19:00

0 Answers0