Re: Retrieving result of COUNT(*) with PHP

From: Frank Bax <fbax(at)sympatico(dot)ca>
To: pgsql-php(at)postgresql(dot)org
Subject: Re: Retrieving result of COUNT(*) with PHP
Date: 2007-03-28 21:03:53
Message-ID: 5.2.1.1.0.20070328164533.009fcdc0@pop6.sympatico.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-php

At 03:16 PM 3/28/07, Lynna Landstreet wrote:
>I'm trying to use a SELECT COUNT(*) to count how many results would be
>retrieved from a particular query (as part of the process of paginating
>search results).
>
>But I'm having trouble figuring out how to retrieve the result of the
>count in PHP.

Why not simply run your query and then call pg_numrows( ) ?

You didn't show us any php code - this works..

$res = pg_query( $dbc, 'SELECT COUNT(*) FROM payperiod');
$val = pg_fetch_result( $res, 0, 0 );
var_dump ($val );

might output something like

string(3) "205"

In response to

Browse pgsql-php by date

  From Date Subject
Next Message Mihail Mihailov 2007-03-28 21:05:11 Re: Retrieving result of COUNT(*) with PHP
Previous Message Gavin M. Roy 2007-03-28 20:48:36 Re: Retrieving result of COUNT(*) with PHP