Received: from bush.rutgersinsurance.com (rutgersinsurance.com [38.138.71.194]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f36HDC857447 for ; Fri, 6 Apr 2001 13:13:12 -0400 (EDT) (envelope-from aalang@rutgersinsurance.com) Received: from 6014cwpza006 (adam.rutgersinsurance.com [10.10.10.51]) by bush.rutgersinsurance.com (8.9.3/8.9.3) with SMTP id NAA24439 for ; Fri, 6 Apr 2001 13:26:39 -0400 Message-ID: <00bd01c0bebd$3183ee00$330a0a0a@rutgersinsurance.com> From: "Adam Lang" To: References: <5.0.2.1.0.20010406095908.009f6050@127.0.0.1> <018101c0beb1$362e59b0$6501a8c0@workstation7> Subject: Re: Sorting after a search Date: Fri, 6 Apr 2001 13:15:35 -0400 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 X-Archive-Number: 200104/8 X-Sequence-Number: 261 I agree. SQL DBs are made to do that stuff. Adam Lang Systems Engineer Rutgers Casualty Insurance Company http://www.rutgersinsurance.com ----- Original Message ----- From: "Steve Werby" To: ; "rickf" Sent: Friday, April 06, 2001 11:49 AM Subject: Re: [PHP] Sorting after a search > "rickf" wrote: > > Currently I have the script below which works fine as far as it goes. > > > > I need to be able to sort on surname (later on other fields based on user > > input). > > > > I tried to work in some of the sort functions like asort but couldn't > get > > any output. > > I suspect the problem lies in passing the values from the first search to > > the sort. > > > > I tried used pg_fetch_array to do the initial search then pass it on to > > asort but without luck. > > Why not add an ORDER BY clause to the SQL statement? It should be much > faster to sort the records within PostgreSQL than within PHP. > > > Ultimately I will be having three search fields, a user pick list for > > fields outputted and sorted on. > > I'd suggest building your SQL statement dynamically. > > $sql = "SELECT * FROM table1 WHERE surname LIKE '$NAME%' "; > if ( $radio[1] == 1 ) { $sql .= 'ORDER BY last_name '; } > else if ( $radio[2] == 1 ) { $sql .= 'ORDER BY first_name '; } > > Then if you're using checkboxes to allow the user to set the fields to > display, loop through the user inputted list and dynamically set the fields > to display. Unless you're using PHP's serialize() and session functions (or > a similar method) you're not going to be able to pass the query results from > page to page to sort anyway - you'll have to requery Postgre every time you > want to change the output on the page based on some user input. > > -- > Steve Werby > President, Befriend Internet Services LLC > http://www.befriend.com/ > > > ---------------------------(end of broadcast)--------------------------- > TIP 2: you can get off all lists at once with the unregister command > (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)