Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 396F7632386 for ; Sun, 19 Apr 2009 09:19:47 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 53855-05 for ; Sun, 19 Apr 2009 09:19:45 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from oberon.wxnz.net (oberon.wxnz.net [58.28.6.13]) by mail.postgresql.org (Postfix) with ESMTP id 5067A632272 for ; Sun, 19 Apr 2009 09:19:44 -0300 (ADT) Received: from gonzo (ip-118-90-128-6.xdsl.xnet.co.nz [118.90.128.6]) by oberon.wxnz.net (Postfix) with ESMTP id 687B04640EE for ; Mon, 20 Apr 2009 00:19:41 +1200 (NZST) Received: from news by gonzo with local (Exim 4.69) (envelope-from ) id 1LvW0C-0005l9-4j for pgsql-php@postgresql.org; Mon, 20 Apr 2009 00:20:04 +1200 To: pgsql-php@postgresql.org Path: not-for-mail From: Jasen Betts Newsgroups: gmane.comp.db.postgresql.php Subject: Re: sorting query results Date: 19 Apr 2009 12:20:03 GMT Organization: Dis (not Dat) Organisation Lines: 33 Message-ID: References: <49E9CFBF.4050808@gmail.com> NNTP-Posting-Host: localhost Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: reversiblemaps.ath.cx 1240143603 21733 127.0.0.1 (19 Apr 2009 12:20:03 GMT) X-Face: ?)Aw4rXwN5u0~$nqKj`xPz>xHCwgi^q+^?Ri*+R(&uv2=E1Q0Zk(>h!~o2ID@6{uf8s; a +M[5[U[QT7xFN%^gR"=tuJw%TXXR'Fp~W; (T"1(739R%m0Yyyv*gkGoPA.$b,D.w:z+<'"=-lVT?6 {T?=R^:W5g|E2#EhjKCa+nt":4b}dU7GYB*HBxn&Td$@f%.kl^:7X8rQWd[NTc"P"u6nkisze/Q; 8 "9Z{peQF,w)7UjV$c|RO/mQW/NMgWfr5*$-Z%u46"/00mx-,\R'fLPe.)^ User-Agent: slrn/pre1.0.0-2 (Linux) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200904/12 X-Sequence-Number: 4017 On 2009-04-18, 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. this is the easiest way, and a good start. > 2. Save the table into php array and and use php built-in functions to > sort and refresh the table. unless you're proposing to store the store the array in $SESSION (or similar) that's not going to work. also you may get issues if the user opens two different queries in different windows... > 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. Here's a third way: use javascript to sort the array. this gives the best user experience but you should arrange the page so that those with script turned off can still get the results using one of the other methods.