I am trying to show, in a dropdown, the students beloging to the same class. But with my current code, the dropdown content for all classes are the same.
I started with these lines of code:
// Get all the classnames
$aAllClasses = $this->fetchAllClasses();
// Create a menubutton foreach classname
foreach($aAllClasses as $aClassname){
echo("<a class='link dropdown-toggle' href='#' id='navbarDropdown' role='button' data-toggle='dropdown' aria-haspopup='true' aria-expanded='false'>".$aClassname[0]." </a>");
// Create the list with students for this class
echo("<ul class='dropdown-menu' aria-labelledby='navbarDropdown'>");
// Get all the students from this class
$aClassStudents = $this->fetchClassStudents($aClassname[0]);
// Create the dropdown list
foreach($aClassStudents as $aStudentRecord){
echo("<li><a class='dropdown-item' href='student.php' data-toggle='tooltip' title='Edit'>".$aStudentRecord['sStudentSurname']."</a></li>");
}
echo("</ul><br>");
}
According to this answer Bootstrap Dropdown shows double? Weird One
I changed
href='#' into href='javascript:void();'
nothing changed. Then I saw at W3schools this snippet https://www.w3schools.com/bootstrap4/bootstrap_dropdowns.asp
Also no joy
On basis of this site I changed the labeling ID's https://www.quackit.com/html/html_editors/scratchpad/?example=/bootstrap/bootstrap_4/tutorial/bootstrap_4_navbars_dropdown_menus
id='#Dropdown".$aClassname[0]."'
aria-labelledby='Dropdown".$aClassname[0]."'
New code:
// Get all the classnames
$aAllClasses = $this->fetchAllClasses();
// Create a menubutton foreach classname
foreach($aAllClasses as $aClassname){
echo("<a class='link dropdown-toggle' href='#' id='#Dropdown".$aClassname[0]."' role='button' data-toggle='dropdown' aria-haspopup='true' aria-expanded='false'>".$aClassname[0]." </a>");
// Create the list with students for this class
echo("<ul class='dropdown-menu' aria-labelledby='Dropdown".$aClassname[0]."'>");
// Get all the students from this class
$aClassStudents = $this->fetchClassStudents($aClassname[0]);
// Create the dropdown list
foreach($aClassStudents as $aStudentRecord){
echo("<li><a class='dropdown-item' href='student.php' data-toggle='tooltip' title='Edit'>".$aStudentRecord['sStudentSurname']."</a></li>");
}
echo("</ul><br>");
}
Also the same result.
if I remove the 'end unordend list' in the last line both classes and students are viewed, but in a nested way.
So now I separated the buttons from the content
$aAllClasses = $this->fetchAllClasses();
foreach($aAllClasses as $aClassname){
echo("<a class='link dropdown-toggle' href='#' id='#navbarDropdown".$aClassname[0]."' role='button' data-toggle='dropdown' aria-haspopup='true' aria-expanded='false'>".$aClassname[0]."</a><br><br>");
}
foreach($aAllClasses as $aClassname){
echo("<ul class='dropdown-menu' aria-labelledby='#navbarDropdown".$aClassname[0]."'>");
$aClassStudents = $this->fetchClassStudents($aClassname[0]);
foreach($aClassStudents as $aStudentRecord){
echo("<li><a class='dropdown-item' href='exa_classes.php' data-toggle='tooltip' title='Edit'>".$aStudentRecord['sStudentSurname']."</a></li>");
}
echo("</ul>");
}
Same result, the content of the second class is still the same as the first. And now I run out of idea's. Can someone tell me why I cant get those dropdowns filled with a different content for each class?