I’m trying to figure out how to echo out content above the while loop and underneath the check for num_rows, but I need to get the content from the while loop before doing that.
$sql = "SELECT * FROM table WHERE column = ?";
$stmt = $db->prepare($sql);
$stmt->bind_param('s', $test);
$result = $stmt->execute();
$stmt_result = $stmt->get_result();
if ($stmt_result->num_rows > 0) {
echo "<div id='wrapper'>"; //I need to echo out rows here if $status === 2
while ($row = $stmt_result->fetch_assoc()) {
$title = $row['title'];
$description = $row['descript'];
$status = $row['status'];
if ($status === 2) {
echo $status;
continue; //skip to the next iteration
}
echo $title;
echo $description;
}
}
How is it done?
To summarize, this is the output I’m looking for:
//if status !== 2: (i get 3 results)
<div id='wrapper'>
//title
//description
//title
//description
//title
//description
</div>
//if status === 2: (i get 1 result)
<div id='other_wrapper'>
//title
//description
</div>
//if status === 3: (i get 5 results)
<div id='yet_another_wrapper'>
//title
//description
//title
//description
//title
//description
//title
//description
//title
//description
</div>