Select Page

mysql_* functions have been removed in PHP 7. You have to use mysqli_ functions.

mysqli_num_rows()

Here is an example:

$conn = new mysqli($servername, $username, $password, $dbname);
$sql = "SELECT `index`, `opendate` FROM open_and_birth GROUP BY `opendate`";
$result = $conn->query($sql);
$num_rows = mysqli_num_rows($result);//計算有多少行
echo $num_rows." results";
$conn->close();

if you using the code below, you will get the error: “mysqli_num_rows() expects parameter 1 to be mysqli_result, string given in”. you need correction your code as above.

$sql = "SELECT `index`, `opendate` FROM open_and_birth GROUP BY `opendate`";
$num_rows = mysqli_num_rows($result);