计算表中的记录

时间:2016-11-15 07:27:01

标签: php

我想在txt框中显示countNum,但它什么也没显示。

我这样做。

 <input type="text" value="<?php $countNum; ?>" disabled = "disabled">

 <?php
    $countNum = "";
    $Q = mysql_query("select * from  blotterreport");

    while ($row = mysql_fetch_array($Q)) {  

        echo "<tr onclick='trClick()'>";
            echo "<td>" . $row["entrynumber"] . "</td>";
            echo "<td>" . $row["natureofcase"] . "</td>";
            echo "<td>" . $row["month"] . " " . $row["day"] . " " . $row["year"] . "</td>";
            echo "<td>" . $row["subject"] . "</td>";
        echo "</tr>";
        $countNum++;
    }
                    echo $countNum;
?>

1 个答案:

答案 0 :(得分:1)

应在$countNum = mysql_num_rows($Q);文字字段之前使用input

<?php 
$Q = mysql_query("select * from  blotterreport");
$countNum = mysql_num_rows($Q);
?>
<input type="text" value="<?php echo $countNum; ?>" disabled = "disabled">
<?php
    while ($row = mysql_fetch_array($Q)) {  
        echo "<tr onclick='trClick()'>";
            echo "<td>" . $row["entrynumber"] . "</td>";
            echo "<td>" . $row["natureofcase"] . "</td>";
            echo "<td>" . $row["month"] . " " . $row["day"] . " " . $row["year"] . "</td>";
            echo "<td>" . $row["subject"] . "</td>";
        echo "</tr>";
    }
?>

注意:请避免使用mysql_*函数,因为已从PHP 7中永久删除mysql_*函数。请使用mysqli_PDO

对于PDO:http://php.net/manual/en/book.pdo.php

对于Mysqli:http://php.net/manual/en/mysqli.examples-basic.php