How to use mysql_num_rows in php

藏色散人
Release: 2023-02-28 15:16:01
Original
2986 people have browsed it

How to use mysql_num_rows in php

How to use mysql_num_rows in php?

Definition and usage

mysql_num_rows() function returns the number of rows in the result set.

Recommended: "PHP Tutorial"

Syntax

mysql_num_rows(data)
Copy after login

Parameters

data required. Result set. This result set is obtained from a call to mysql_query().

Description

mysql_num_rows() returns the number of rows in the result set. This command is only valid for SELECT statements. To get the number of rows affected by an INSERT, UPDATE, or DELETE query, use mysql_affected_rows().

Tips and Notes

Note: If you use mysql_unbuffered_query(), mysql_num_rows() cannot return the correct value until all rows in the result set have been fetched.

Example

<?php
$con = mysql_connect("localhost", "hello", "321");
if (!$con)
  {
  die(&#39;Could not connect: &#39; . mysql_error());
  }
$db_selected = mysql_select_db("test_db",$con);
$sql = "SELECT * FROM person";
$result = mysql_query($sql,$con);
echo mysql_num_rows($result);
mysql_close($con);
?>
Copy after login

Output similar to:

3
Copy after login

The above is the detailed content of How to use mysql_num_rows in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template