我想在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;
?>
答案 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
。