pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tommy Gildseth <gildseth@start.no>
To: Reed Loefgren <rloef@interfold.com>
Cc: pgsql-php@postgresql.org
Subject: Re: PHP Newbie- Display Aggregates in HTML Table
Date: Sat, 29 Apr 2006 23:08:04 +0200
Message-ID: <4453D5B4.3070207@start.no> (raw)
In-Reply-To: <20060426073420.Q3269@auden.jmla.com>
References: <20060426073420.Q3269@auden.jmla.com>

Reed Loefgren wrote:
> All,
> 
> I have a query that returns data that includes a sum(). I can't get this 
> sum to display in an html table. Like so (in part):
> 
> Example bit:
> 
> psql test: select code, blah, sum(time) from test;
> 
> Portion of PHP table code:
> 
> while($myrow = pg_fetch_assoc($result)) {
>     printf ("<tr><td>%s</td><td>%s</td><td>%s</td></tr>",
>       $myrow['code'], $myrow['blah'], $myrow['<what goes here?>']);


To display the result of an function, it's usually best to alias the 
value, like so: select code, blah, sum(time) AS the_sum from test;
That way, you can use $myrow['the_sum'] to access that value. You could 
also do $myrow['sum(time)'], but it doesn't, imo, look very nice.

The reason why your query doesn't work, is because you're trying to use 
an agregate function without a group by clause. ...Which would work 
fine, if you did just SELECT sum(time) FROM test, but not when you do 
SELECT code, blah, sum(time) FROM test.

Tommy



view thread (2+ messages)

Message-ID: <4453D5B4.3070207@start.no>
Permalink:  ../4453D5B4.3070207@start.no/
Also on:    postgresql.org/message-id/4453D5B4.3070207@start.no

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-php@postgresql.org
  Cc: gildseth@start.no, rloef@interfold.com
  Subject: Re: PHP Newbie- Display Aggregates in HTML Table
  In-Reply-To: <4453D5B4.3070207@start.no>
  References: <20060426073420.Q3269@auden.jmla.com> <4453D5B4.3070207@start.no>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox