pg_num_rows

(PHP 4 >= 4.2.0, PHP 5)

pg_num_rows -- Returns the number of rows in a result

Описание

int pg_num_rows ( resource result )

pg_num_rows() will return the number of rows in a PostgreSQL result resource.

Замечание: This function used to be called pg_numrows().

Список параметров

result

PostgreSQL query result resource, returned by pg_query(), pg_query_params() or pg_execute() (among others).

Возвращаемые значения

The number of rows in the result. On error, -1 is returned.

Примеры

Пример 1. pg_num_rows() example

<?php
$result
= pg_query($conn, "SELECT 1");

$rows = pg_num_rows($result);

echo
$rows . " row(s) returned.\n";
?>

Результат выполнения данного примера:

1 row(s) returned.

Смотрите также

pg_num_fields()
pg_affected_rows()



pg_num_rows
php-docs (at) radev (dot) net
23-Mar-2005 07:16
Yet even simpler example:

$query = "SELECT * FROM atable";
$result = pg_query($query);

if (pg_num_rows($result)>0) {
  while($row=pg_fetch_object($result) {
   echo $row->first_column;
   echo $row->second_column;
   ....
   echo $row->last_column;
  }
}
else {
  echo "The query did not return any data!";
}
aron at lurie dot biz
02-Nov-2003 05:23
Simple example

$sql = "select * from YOURTABLE";
$result = pg_query($sql);
$rows = pg_num_rows($result);
for ($i = 0; $i < $rows; $i++)
{
   $data = pg_fetch_object($result, $i);
   echo "$data->COLUMNNAME";
}
flavio AT catalani.net
14-Jan-2003 10:39
simple pg_num_fields & pg_num_rows example.

$result = pg_query($conn, $string);

while($arr = pg_fetch_array ($result)) {
     for ($x=0;$x<=pg_num_fields($result);$x++)
           print $arr[$x] . " ";
     print "\n";
}

adapted (stolen) from php manual ;)
sean at seattleone dot com
21-Oct-2002 07:27
Simple Example:

$result = pg_query($conn_id, $query);
echo pg_num_rows($result);

<pg_num_fieldspg_options>
 Last updated: Tue, 15 Nov 2005