Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 41253632B8D for ; Sat, 18 Apr 2009 19:32:43 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 85040-06 for ; Sat, 18 Apr 2009 19:32:35 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-fx0-f174.google.com (mail-fx0-f174.google.com [209.85.220.174]) by mail.postgresql.org (Postfix) with ESMTP id B0737632A9A for ; Sat, 18 Apr 2009 19:32:39 -0300 (ADT) Received: by fxm22 with SMTP id 22so1943231fxm.19 for ; Sat, 18 Apr 2009 15:32:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:cc:subject:references:in-reply-to :content-type:content-transfer-encoding; bh=Qze9aAaE2WuHAZv6X6aBZTJ4k3E8sJb48ZsJWnyjl8c=; b=d6QYfZYhi+jNhnpSRd2CBngppYMzo2m4eGL9pi9UffsuaIGpN7VwBB7TPnsMx82xSC V85EGZXDIbOPanwX1RWU8zDUq9zL5qPLIi3iboY4ebpiQydvi/b1lSfq8Rz+9bQgJyIq IwF8eshfYK4djkljQcTYhYpps2m2Qt24zkRXA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; b=oTIx1OkGEnITQXkNF7D47bY2WUl/wANPQazf0pBanhd47wEuyzwTXR34Z35Hus/DfR Ik6a0PqM4u9NerpF2s5yQzWHpkxZjDiibtT5JXsWkaZ6/h4KhXGZz6Q37OolHJcw+QLh Yk47VdqbkWDJccziiOkl7YgfA8Fg7kleYE1O0= Received: by 10.86.31.18 with SMTP id e18mr2906906fge.72.1240093958360; Sat, 18 Apr 2009 15:32:38 -0700 (PDT) Received: from ?192.168.0.100? (as67-120.tontut.fi [94.237.67.120]) by mx.google.com with ESMTPS id 12sm2643004fgg.7.2009.04.18.15.32.37 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sat, 18 Apr 2009 15:32:38 -0700 (PDT) Message-ID: <49EA5504.6090705@gmail.com> Date: Sun, 19 Apr 2009 01:32:36 +0300 From: Piotr Mitoraj User-Agent: Thunderbird 2.0.0.21 (X11/20090318) MIME-Version: 1.0 To: Andrew McMillan CC: pgsql-php@postgresql.org Subject: Re: sorting query results References: <49E9CFBF.4050808@gmail.com> (sfid-20090419_010444_776307_BC32543F) <1240090275.9028.948.camel@happy.mcmillan.net.nz> In-Reply-To: <1240090275.9028.948.camel@happy.mcmillan.net.nz> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200904/11 X-Sequence-Number: 4016 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