需要计算 PHP 中创建的列表的结果
Need to Count results of a list created in PHP
好的,我有一个列表正在填充并在页面上回显。
$sql = "SELECT * FROM `game_toe` WHERE `owner`='$mech_units'";
$mydata = mysql_query($sql);
while($record = mysql_fetch_array($mydata)){
echo "<td>" . $record['units'] . "</td>";
现在结果会随着 'mech_units' 的数量而波动。我需要的是显示列表中显示的数量。有什么建议吗?
首先,我建议使用mysqli。
您可以声明一个变量,每次回显 'mech_unit'。
$sql = "SELECT * FROM `game_toe` WHERE `owner`='$mech_units'";
$mydata = mysql_query($sql);
$i = 0;
while($record = mysql_fetch_array($mydata)){
$i++;
echo "<td>" . $record['units'] . "</td>";
}
echo "There are " . $i . " mech_units.";
另一种选择是使用 mysql_num_rows()
函数。
您可以使用内置函数 mysql_num_rows($mydata)
。这将为您提供已提取的记录总数。
好的,我有一个列表正在填充并在页面上回显。
$sql = "SELECT * FROM `game_toe` WHERE `owner`='$mech_units'";
$mydata = mysql_query($sql);
while($record = mysql_fetch_array($mydata)){
echo "<td>" . $record['units'] . "</td>";
现在结果会随着 'mech_units' 的数量而波动。我需要的是显示列表中显示的数量。有什么建议吗?
首先,我建议使用mysqli。
您可以声明一个变量,每次回显 'mech_unit'。
$sql = "SELECT * FROM `game_toe` WHERE `owner`='$mech_units'";
$mydata = mysql_query($sql);
$i = 0;
while($record = mysql_fetch_array($mydata)){
$i++;
echo "<td>" . $record['units'] . "</td>";
}
echo "There are " . $i . " mech_units.";
另一种选择是使用 mysql_num_rows()
函数。
您可以使用内置函数 mysql_num_rows($mydata)
。这将为您提供已提取的记录总数。