Lets say for example there are 5 records shown on screen. I want the $questionnum to display the number 5, but it keeps stating that $questionnum is 0. How Can I get the number of the number of rows actually match with the number of rows which are outputted on screen. E.G if 5 rows then display number 5, if 3 rows display number 3 and etc.
Below is code:
// Execute
if (!$stmt->execute()) {
die("Error executing statement: $stmt->error");
}
$stmt->store_result();
// This will hold the search results
$searchResults = array();
$searchOption = array();
// Fetch the results into an array
if (!$stmt->num_rows()) {
$stmt->bind_result($dbQuestionContent,$dbOptionType);
while ($stmt->fetch()) {
$searchResults[] = $dbQuestionContent;
$searchOption[] = $dbOptionType;
}
}
if (isset($_GET['searchQuestion'])) {
// If $terms is not empty we did a query
if (!empty($terms)) {
$questionnum = $stmt->num_rows;
// If $searchResults is not empty we got results
if (!empty($searchResults)) {
echo"<p>Number of Questions Shown from the Search: <strong>$questionnum</strong></p>";
echo "<table border='1' id='resulttbl'>
foreach ($searchResults as $key=>$question) {
echo '<tr class="questiontd"><td>'.htmlspecialchars($question).'</td>';
echo '<td class="optiontypetd">'.htmlspecialchars($searchOption[$key]).'</td>';
}
echo "</table>";
}
Since you are already storing results in the array, just do