mysql_num_rows

2009-05-27 16:22 / no comment / 31 views /

PHP 4, PHP 5中可用。获得查询结果的行数。

函数声明

int _num_rows ( resource $result )
检索结果中的行数。这和命令只对SELECT或SHOW这类函数返回的查询结果可用。要检索受到插入、更新、替换或删除操作影响的行数,要使用mysql_affected_rows()

参数

result
要被评估的结果参数。这个参数来自于mysql_query()调用。

返回值

运行成功则返回结果中的行数,运行失败则返回FALSE。

示例

Example #1 mysql_num_rows() example
<?php

$link = mysql_connect(“localhost”, “mysql_user”, “mysql_password”);
mysql_select_db(“database”, $link);

$result = mysql_query(“SELECT * FROM table1″, $link);
$num_rows = mysql_num_rows($result);

echo “$num_rows Rowsn”;

?>

注意

如果你使用mysql_unbuffered_query(),mysql_num_rows()将不会返回正确的值,直到结果所有的行都被检索。
为了向后兼容,下面这个别名可能被使用:mysql_numrows()。

同样请看

* mysql_affected_rows() – Get number of affected rows in previous MySQL operation
* mysql_connect() – 打开一个到MySQL的连接
* mysql_data_seek() – Move internal result pointer
* mysql_select_db() – Select a MySQL database
* mysql_query() – Send a MySQL query

原文:http://www.php.net/manual/en/function.mysql-num-rows.php

Related Posts

  1. mysql_data_seek
  2. PHP中的MySQL函数
  3. mysql_db_query
  4. mysql_query
  5. mysql_affected_rows
  6. mysql_create_db
  7. mysql_drop_db
  8. mysql_error
  9. mysql_change_user
  10. mysql_db_name

Tags: .

Get a Trackback link

No Comments Yet

You can be the first to comment!

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>