PHP Tutorial

Español Français 中文 Deutsch Portuguese Japanese nederlands
PHP Topics
Introduction Introduction
Syntax Syntax
Data Types Data Types
Operators Operators
Control Structures Control Structures
Functions Functions
Pre-defined Function Pre-defined Function
Calendar Functions Calendar Functions
Date and Time Date and Time
Array Functions Array Functions
Array List Array Functions List1
Array Function List Array Functions List2
Math Functions Math Functions
PHP MYSQL Functions PHP Mysql Functions
File Handling File Handling
Error Handling Error Handling
DB Size DB Size
PHP Mail PHP Mail
String Tokens String Tokens
String Functions String Functions
String Functions List String Functions List1
String Functions List2 String Functions List2
Session Functions Session Functions
Cookies Functions Cookies Functions
Form Variables Form Variables
Examining variables Examining variables
Filter Functions Filter Functions
PHP Filters PHP Filters
Running PHP from JS Running PHP from JS
Array To JS Array To JS
JS Array Array to PHP
Encryption Encryption
Common Header Common Header
Forums Ask Your Doubts
Scraps More about PHP
Feedback Feedback

mysql_num_rows() function in PHP

  Tutorials  Php 


What is mysql_num_rows() function in PHP?
How does mysql_num_rows() works?


This mysql_num_rows function in php returns number of rows in result.

int mysql_num_rows ( resource $result )

Returns number of rows in result on success, or NULL on error.

mysql_num_rows () function retrieves the number of rows from a result set. This command is only valid for statements like SELECT or SHOW that return an actual result set. To retrieve the number of rows affected by a INSERT, UPDATE, REPLACE or DELETE query, use mysql_affected_rows().



//Attempt to connect to the default database server
$link = mysql_connect("mysql_host", "mysql_user", "mysql_password")
or die ("Could not connect");

mysql_select_db("database", $link);
$result = mysql_query("SELECT * FROM table1", $link);

//returns number of rows in result
$num_rows = mysql_num_rows($result);

//Print number of rows
echo "$num_rows Rows\n";



10 Rows

See also:

Other Links

web hosting