Skip site navigation (1) Skip section navigation (2)

Re: sorting query results

From: Andrew McMillan <andrew(at)morphoss(dot)com>
To: Piotr Mitoraj <piotr(dot)mitoraj(at)gmail(dot)com>
Cc: pgsql-php(at)postgresql(dot)org
Subject: Re: sorting query results
Date: 2009-04-18 21:31:15
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-php
On Sat, 2009-04-18 at 16:03 +0300, Piotr Mitoraj wrote:
> Hi,
> failing to find the straight-forward answer on the web I hope to find 
> some advice in here.
> I want to display the table fetched from the postgres database. The 
> headers of the columns are links used to sort the data. Like the 
> functionality you have on ebay when you sort according to price or time 
> left. I recognized two ways of doing that:
> 1. Issue a new query to the database each time the specific sorting was 
> requested. In other words, let the database do the sorting and fetch the 
> results.
> 2. Save the table into php array and and use php built-in functions to 
> sort and refresh the table.
> Which of those methods would be most desired in terms of performance and 
> according to "the best practices"?
> What would be possible drawbacks/advantages of those methods.

Personally I've found it easiest to implement the sorting in database.
The reason this is easier is that the programming involved is just a
small change to the 'ORDER BY' clause in the SQL, whereas the sorting in
PHP would often change the whole way the query results are processed.

Another approach I have seen used, which you don't mention, is to do the
sorting in javascript, client side.  This has the advantage that the
database is only queried the first time and all re-sorting is done
client-side.  In this case sorting on things like time/date data can be
more problematic, and of course you're depending client-side behaviour


andrew (AT) morphoss (DOT) com                            +64(272)DEBIAN
          Powering the .NZ namespace with Open Source Software

In response to


pgsql-php by date

Next:From: Piotr MitorajDate: 2009-04-18 22:32:36
Subject: Re: sorting query results
Previous:From: L. FranklinDate: 2009-04-18 14:40:34
Subject: Re: sorting query results

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group