PHP Velho Oeste 2024

fbsql_num_rows

(PHP 4 >= 4.0.6, PHP 5 < 5.3.0)

fbsql_num_rows結果のレコード数を得る

説明

fbsql_num_rows ( resource $result ) : int

指定した結果セット result の行数を取得します。

このコマンドは SELECT 文に対してのみ使用可能です。 INSERT、UPDATE あるいは DELETE クエリの行数を取得するには、 fbsql_affected_rows() を使用します。

パラメータ

result

fbsql_query() あるいは fbsql_db_query() が返す結果 ID。

返り値

直近の SELECT 文が返す行の数を返します。

例1 fbsql_num_rows() の例

<?php

$link 
fbsql_connect("localhost""username""password");
fbsql_select_db("database"$link);

$result fbsql_query("SELECT * FROM table1;"$link);
$num_rows fbsql_num_rows($result);

echo 
"$num_rows Rows\n";

?>

参考

add a note add a note

User Contributed Notes 1 note

up
0
daggillies at yahoo dot com
22 years ago
Note that this function will not always return the actual size of a result set. For example, if you are doing a two-table join along the lines of "SELECT * FROM T1,T2 where T1.x=T2.x" you will get a result of -1. This is due to the 'lazy execution' model in FrontBase whereby result rows are only returned as you request them. If you absolutely have to have the number of rows in advance then you will have to use COUNT(*) first. Most of the time you do not need to know the exact number of rows; it is good enough to know if the size of the result set is non-zero.

David Gillies
San Jose
Costa Rica
To Top