Thread: problem with round() in php script
hi,
In pgadmin3 this query works ok.
SELECT name,round(ges_kw,0)
FROM energie.tennet_auswertung_2010;
but in php 5.3.2 the result is 0 for all rows
$result = pg_query('
SELECT name,round(ges_kw,0)
FROM energie.tennet_auswertung_2010
');
What should I do to round up to 0 decimal places?
yours with thanks,
Rob
On 06/10/2011 08:59, Robert Buckley wrote: > hi, > > In pgadmin3 this query works ok. > > SELECT name,round(ges_kw,0) > FROM energie.tennet_auswertung_2010; > > but in php 5.3.2 the result is 0 for all rows > > $result = pg_query(' > SELECT name,round(ges_kw,0) > FROM energie.tennet_auswertung_2010 > '); The first parameter in pg_query() is supposed to be the connection returned by pg_connect() - the docs say that it can be omitted, but that's not recommended. Have you tried it with the connection included? Ray. -- Raymond O'Donnell :: Galway :: Ireland rod@iol.ie
Im not quite sure what you are referring to....this is my php code. The connection is included, but not in the sql query!
<?
$connection=pg_connect("host=*** port=*** dbname=zgb user=*** password=***");
SELECT name,round(ges_kw,0)
FROM energie.tennet_auswertung_2010
');
$rows = array();
while($r = pg_fetch_assoc($result)) {
$rows[] = $r;
}
print json_encode(array_values(pg_fetch_all($result)));
?>
Von: Raymond O'Donnell <rod@iol.ie>
An: Robert Buckley <robertdbuckley@yahoo.com>
Cc: "pgsql-general@postgresql.org" <pgsql-general@postgresql.org>
Gesendet: 10:42 Donnerstag, 6.Oktober 2011
Betreff: Re: [GENERAL] problem with round() in php script
On 06/10/2011 08:59, Robert Buckley wrote:
> hi,
>
> In pgadmin3 this query works ok.
>
> SELECT name,round(ges_kw,0)
> FROM energie.tennet_auswertung_2010;
>
> but in php 5.3.2 the result is 0 for all rows
>
> $result = pg_query('
> SELECT name,round(ges_kw,0)
> FROM energie.tennet_auswertung_2010
> ');
The first parameter in pg_query() is supposed to be the connection
returned by pg_connect() - the docs say that it can be omitted, but
that's not recommended. Have you tried it with the connection included?
Ray.
--
Raymond O'Donnell :: Galway :: Ireland
rod@iol.ie
On 06/10/2011 10:02, Robert Buckley wrote: > Im not quite sure what you are referring to....this is my php code. The > connection is included, but not in the sql query! > > <? > > $connection=pg_connect("host=*** port=*** dbname=zgb user=*** > password=***"); > > $result = pg_query(' > SELECT name,round(ges_kw,0) > FROM energie.tennet_auswertung_2010 > '); What I was suggesting was that you try it this way: $connection = pg_connect(.... $result = pg_query($connection, 'select..... IOW, you pass $connection as the first argument to pg_query(). See the PHP docs here: http://ie.php.net/manual/en/function.pg-query.php Ray. -- Raymond O'Donnell :: Galway :: Ireland rod@iol.ie