From: Piotr Mitoraj <piotr.mitoraj@gmail.com>
To: Andrew McMillan <andrew@morphoss.com>
Cc: pgsql-php@postgresql.org
Subject: Re: sorting query results
Date: Sun, 19 Apr 2009 01:32:36 +0300
Message-ID: <49EA5504.6090705@gmail.com> (raw)
In-Reply-To: <1240090275.9028.948.camel@happy.mcmillan.net.nz>
References: <49E9CFBF.4050808@gmail.com>
<1240090275.9028.948.camel@happy.mcmillan.net.nz>
Andrew McMillan wrote:
> 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
> also.
>
> Cheers,
> Andrew.
>
> ------------------------------------------------------------------------
> andrew (AT) morphoss (DOT) com +64(272)DEBIAN
> Powering the .NZ namespace with Open Source Software
> ------------------------------------------------------------------------
>
>
Thanks for advice Lukass and Andrew. Tablesorter really made my day!
Previously I was not even considering javascript, but for my purpose
seems to be the best.
Quick links for reference just in case anyone else got interested:
http://tablesorter.com/docs/http://docs.jquery.com/Main_Page
Piotr
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: piotr.mitoraj@gmail.com, andrew@morphoss.com
Subject: Re: sorting query results
In-Reply-To: <49EA5504.6090705@gmail.com>
References: <49E9CFBF.4050808@gmail.com> <1240090275.9028.948.camel@happy.mcmillan.net.nz> <49EA5504.6090705@gmail.com>
* 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