From: | rickf <rickf(at)dufferinresearch(dot)com> |
---|---|
To: | pgsql-php(at)postgresql(dot)org |
Subject: | Sorting after a search |
Date: | 2001-04-06 14:15:45 |
Message-ID: | 5.0.2.1.0.20010406095908.009f6050@127.0.0.1 |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-php |
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(at)dufferinresearch(dot)com
________________________________
From | Date | Subject | |
---|---|---|---|
Next Message | Steve Werby | 2001-04-06 15:49:47 | Re: Sorting after a search |
Previous Message | Adam Lang | 2001-04-06 13:24:23 | Re: Wildcard queries via PHP4 |