Hey guys!
From my understanding, if I have more than one queries, how can I go about in using some of the previous queries? Let’s say that I have the following code but need to access query 1 and 2, 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";
}
Because I am trying to query $row[‘name’] but can’t get it to do so…