例如,屏幕上显示 5 条记录。我希望 $questionnum 显示数字 5,但它一直说 $questionnum 为 0。我怎样才能获得与屏幕上输出的行数实际匹配的行数。EG 如果 5 行则显示数字 5,如果 3 行则显示数字 3 等等。
下面是代码:
 // 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>";
    }