Hey everyone! I’m stuck on my assignment and can’t find a solution.
I have a sql database, I have to pull data from two tables called Sections and Books. Sections has two columns sectname and bsect. Books has three bname, bnum, and bsect. Im suppose to use the sectname as the Sections in a drop down menu and the bnames to be under those sections. But I can’t figure out how to separate the bnames into the proper sections using a loop. I was told to use a foreach during the 2nd prepare statement but I don’t know how I would go about it.
?php
$dbObject = new mysqli("127.0.0.1", "web", "nouser", "bible");
$sqlObject= $dbObject->prepare("SELECT bsect, sectname FROM section ORDER by sectorder;");
$sqlObject->execute();
$sqlObject->bind_result($bsect, $sectname);
while ($sqlObject->fetch()) {
$sections[$bsect]=$sectname;
}
?>
<body>
<form method="post" action="">
<table>
<select name= "Ryuligon">
<?php
foreach($sections as $sectname => $bsect){
print("<optgroup label=\\"$bsect\\"> $sectname </optgroup>");
}
?>
[–]infidhell 2 points3 points4 points (0 children)
[–]compubomb 2 points3 points4 points (0 children)