我正在尝试使用count函数计算表中的行数。我目前在表中有5行。但是计数功能只计算1行。为什么是这样?任何建议。
$count_pcode = mysqli_query($dbc, "SELECT COUNT(*)FROM Delivery_Pcode");
$count_row =mysqli_num_rows($count_pcode);
printf("%d results.\n",$count_row);
mysqli_free_result($count_pcode );
mysqli_close($dbc);
答案 0 :(得分:2)
只需将第一行更改为:
$count_pcode = mysqli_query($dbc, "SELECT * FROM Delivery_Pcode");
下一行代码将告诉您查询返回的行数
$count_row =mysqli_num_rows($count_pcode);
答案 1 :(得分:2)
此代码应计算行数,并有效地执行此操作。
$result = mysql_query($dbc, "SELECT COUNT(*)FROM Delivery_Pcode");
// Verify it worked
if (!$result) echo mysql_error();
$row = mysql_fetch_row($result);
// Should show you an integer result.
print_r($row);
mysqli_free_result($result);
mysqli_close($dbc);
答案 2 :(得分:1)
尝试以下方法:
$count_pcode = mysqli_query($dbc, "SELECT * FROM Delivery_Pcode");
$count_row = mysqli_num_rows($count_pcode);