pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: rickf <rickf@dufferinresearch.com>
To: pgsql-php@postgresql.org
Subject: Sorting after a search
Date: Fri, 06 Apr 2001 10:15:45 -0400
Message-ID: <5.0.2.1.0.20010406095908.009f6050@127.0.0.1> (raw)

Many thanks to all who responded & helped with my last query.
Does anyone have any suggestions on a good online resource (with examples)
where I can find out how to process a query then sort the output a key 
(which is the field used for the search)
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.

Ultimately I will be having three search fields, a user pick list for 
fields outputted and sorted on.
As you can see I'm a long way from there :-)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 //EN">
<?PHP
if ( strlen($NAME) >0):
         $NAME = addslashes($NAME);
         $NAME = strtolower($NAME);
         $NAME = ucfirst($NAME);
$conn = pg_Connect("dbname=test_db port=5432");
         if(!$conn) { echo "Error in connecting to DB\n"; exit;  }
                 $result = pg_Exec($conn, "SELECT * FROM table1 WHERE 
surname LIKE '$NAME%' ");
         if(!$result) { echo "Error in output\n"; exit;  }
$num = pg_NumRows($result);
         echo "<br><table border=\"2\">There are $num records that start 
with  $NAME in the surname 
field 
<br>_____________________________________________________________________________________________________________________________________</table>"; 


$i=0;
while ($i < $num)
{
         $cto_from = pg_Result($result, $i, "to_from");
         $ctitle = pg_Result($result, $i, "title");
         $crank = pg_Result($result, $i, "rank");
         $cother = pg_Result($result, $i, "other");
         $cname = pg_Result($result, $i, "surname");
         $cdate = pg_Result($result, $i, "date");
         $cact_date = pg_Result($result, $i, "act_date");
         $cws_add = pg_Result($result, $i, "ws_add");
         $csend_add = pg_Result($result, $i, "send_add");
         $crecp_add = pg_Result($result, $i, "recp_add");
         $csalutn = pg_Result($result, $i, "salutn");
         $copen =  pg_Result($result, $i, "open_wds");
         $cpr_loc = $cid  =  pg_Result($result, $i, "pr_loc");
         $cdoc_type = pg_Result($result, $i, "doc_type");
         $cms_loc =  pg_Result($result, $i, "ms_loc");
         $cms_numb = pg_Result($result, $i, "ms_numb");
         $cms_folio = pg_Result($result, $i, "ms_folio");
         $ctrans = pg_Result($result, $i, "trans");
         $cdatenote = pg_Result($result, $i, "datenote");
         $ctextnote = pg_Result($result, $i, "textnote");
         $cid  =  pg_Result($result, $i, "id");
         $cbio =  pg_Result($result, $i, "bio");

echo "<table border=2><tr><td>DB Number</td><td> $cid 
</td><td>$cto_from</td><td>$crank $ctitle  $cother 
$cname</td><td>Dated</td><td>$cact_date ($cdate)</td><tr><td>MS 
Location</td><td>$cms_loc  $cms_numb $cms_folio</td><td>Opening 
words</td><td>$csalutn $copen 
</td><tr>_____________________________________________________________________________________________________________________________________</tr></table>";

$i++;
}
echo "<p> <a href='index.shtml'>Home</a>";
exit;
endif;
?>
<html>
<head>
<title> Database access test</title>
</head>
<body>
<form method='PUT' action='db.php'>
<center>
<h1><i>Test Database.</i></h1>
<table>
<tr><td> <h3>Please enter the surname (or the beginning letters of the 
name) you wish to query </h3></font></td>
<tr><td> <input type="text" NAME="NAME" VALUE ="" SIZE=40 MAXLENGTH=40>
<BR>
  </td></tr>
  </table>
<input type=submit name=submit value="Press to Query">
</center>a
</body>
</html>


Rick Frank
(mailto:rickf@dufferinresearch.com
________________________________

view thread (3+ messages)  latest in thread

Message-ID: <5.0.2.1.0.20010406095908.009f6050@127.0.0.1>
Permalink:  ../5.0.2.1.0.20010406095908.009f6050@127.0.0.1/
Also on:    postgresql.org/message-id/5.0.2.1.0.20010406095908.009f6050@127.0.0.1

 · 

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: rickf@dufferinresearch.com
  Subject: Re: Sorting after a search
  In-Reply-To: <5.0.2.1.0.20010406095908.009f6050@127.0.0.1>
  References: <5.0.2.1.0.20010406095908.009f6050@127.0.0.1>

* 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