Received: from [128.27.0.226] (mail.dufferinresearch.com [216.58.99.248]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f36EIN829064 for ; Fri, 6 Apr 2001 10:18:23 -0400 (EDT) (envelope-from rickf@dufferinresearch.com) Received: from RICK.DUFFERINRESEARCH.COM by 128.27.0.226 with SMTP (QuickMail Pro Server for MacOS 1.1.2); 06-Apr-2001 10:17:55 -0400 Message-Id: <5.0.2.1.0.20010406095908.009f6050@127.0.0.1> X-Sender: rickf/128.27.0.226@127.0.0.1 X-Mailer: QUALCOMM Windows Eudora Version 5.0.2 Date: Fri, 06 Apr 2001 10:15:45 -0400 To: pgsql-php@postgresql.org From: rickf Subject: Sorting after a search Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="=====================_1456022==_.ALT" X-Archive-Number: 200104/6 X-Sequence-Number: 259 --=====================_1456022==_.ALT Content-Type: text/plain; charset="us-ascii"; format=flowed 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 :-) 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 "
There are $num records that start with $NAME in the surname field
_____________________________________________________________________________________________________________________________________
"; $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 "_____________________________________________________________________________________________________________________________________
DB Number $cid $cto_from$crank $ctitle $cother $cnameDated$cact_date ($cdate)
MS Location$cms_loc $cms_numb $cms_folioOpening words$csalutn $copen
"; $i++; } echo "

Home"; exit; endif; ?> Database access test

Test Database.

Please enter the surname (or the beginning letters of the name) you wish to query


a Rick Frank (mailto:rickf@dufferinresearch.com ________________________________ --=====================_1456022==_.ALT Content-Type: text/html; charset="us-ascii" 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
________________________________

--=====================_1456022==_.ALT--