NUM_ROWS个问题根本不会写出任何内容

时间:2012-05-28 18:29:29

标签: php mysqli

嘿,这就是我必须这样做,如果数据库找不到任何与数据库相匹配的东西或者能找到任何东西那么它应该出现并说些什么,但我完全决心如何构建它在。我会听到可以帮助我

我尝试这样做:

<?php
if ($stmt = $mysqli->prepare('SELECT id_forum, title, tekst, dato, id_brugere FROM `forum` ORDER BY `forum`.`id` DESC'))
{
   $stmt->execute();
   $stmt->bind_result($id, $djnavn, $profilbillede);
   $rows = $stmt->num_rows;
   echo $rows;

   while ($stmt->fetch())
   {
   ?>
      <td class="titleforum"></td>
      <td>Dato:</td>
   <?php
   }
   $stmt->close();
}
else
   $row_cnt = $result->num_rows;
   print_r($row_cnt);
?>

但它似乎没有任何说话或看起来像什么..我想要的是它说的东西?

1 个答案:

答案 0 :(得分:0)

尝试:

<?php
if ($stmt = $mysqli -> prepare('SELECT id_forum, title, tekst, dato, id_brugere FROM `forum` ORDER BY `forum`.`id` DESC'))
{
   $stmt -> execute();
   $stmt -> store_result();

   $rows = $stmt -> num_rows;
   echo $rows;

   while ($stmt -> fetch()) {
?>
      <td class="titleforum"></td>
      <td>Dato:</td>
   <?php
   }
   $stmt->close();
}
?>

请参阅:http://php.net/manual/en/mysqli-stmt.num-rows.php