Hey guys!
I have part of the following code and I am just wondering whether it is possible to use a previous query? I am not sure whether it is the problem with the {} but I have tried to move my echo statement around but it can’t seem to pick up the $row variables within my $row2 statement? I can’t get $row[‘name’]; to work… or must i query it again?
$sql2 = "SELECT * FROM forum_cats WHERE admin < ?;";
if(!mysqli_stmt_prepare($stmt, $sql2)) {
echo "SQL error";
} else {
mysqli_stmt_bind_param($stmt, "i", $admin_user_level);
mysqli_stmt_execute($stmt);
$result2 = mysqli_stmt_get_result($stmt);
while ($row = mysqli_fetch_assoc($result2)) {
$row = $row['id'];
$sql3 = "SELECT * FROM forum_sub_cats WHERE cid = ?;";
if(!mysqli_stmt_prepare($stmt, $sql3)) {
echo "SQL error";
} else {
mysqli_stmt_bind_param($stmt, "i", $row);
mysqli_stmt_execute($stmt);
$result3 = mysqli_stmt_get_result($stmt);
echo "<option value=\"0\">".$row['name']."</option>\n";
while ($row2 = mysqli_fetch_assoc($result3)) {
$selected = ($row2['id'] == $id) ? "SELECTED": "";
echo "<option value=\"".$row2['id']."\"".$selected."> ".$row2['name']."</option>\n";
}