pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Steve Werby <steve-lists@befriend.com>
To: pgsql-php@postgresql.org
To: rickf <rickf@dufferinresearch.com>
Subject: Re: Sorting after a search
Date: Fri, 6 Apr 2001 11:49:47 -0400
Message-ID: <018101c0beb1$362e59b0$6501a8c0@workstation7> (raw)
References: <5.0.2.1.0.20010406095908.009f6050@127.0.0.1>

"rickf" <rickf@dufferinresearch.com> 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/




view thread (3+ messages)  latest in thread

Message-ID: <018101c0beb1$362e59b0$6501a8c0@workstation7>
Permalink:  ../018101c0beb1$362e59b0$6501a8c0@workstation7/
Also on:    postgresql.org/message-id/018101c0beb1$362e59b0$6501a8c0@workstation7

 · 

reply

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: steve-lists@befriend.com, rickf@dufferinresearch.com
  Subject: Re: Sorting after a search
  In-Reply-To: <018101c0beb1$362e59b0$6501a8c0@workstation7>
  References: <5.0.2.1.0.20010406095908.009f6050@127.0.0.1> <018101c0beb1$362e59b0$6501a8c0@workstation7>

* 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