Gossamer Forum
Home : Products : DBMan : Customization :

Sorting a search by date

Quote Reply
Sorting a search by date
JP,
the last advice you game me worked great! Now, I have another question. I have been through the forum, and I can't find anyone who is doing what i want to do (figures). I want to the search to be listed by numerical order of a field that I put in. It's the date in a four digit year format. Is there anyway for dbman to list it from oldest to newest?

Thanks again! You are a life-saver!

Greg

I have a BIG question still to come, but I am trying to figure it out on my own, but don't be surprized if I ask for help again....
Smile :-)
Quote Reply
Re: Sorting a search by date In reply to
It should sort by the field if you have the field type set to "numer" and you have the "sb" field on your form.

If you want to always search by the same field, in sub html_view_search, just after

<input type=hidden name="uid" value="$db_uid">

add

Code:
<input type=hidden name="sb" value="field number of year field">

Make sure you use the number of the field and not the name.


------------------
JPD





Quote Reply
Re: Sorting a search by date In reply to
Carol, if he wants
Code:
<input type=hidden name="so" value="ascend">

Or does it default to ascending order if there is no "so" form variable?

Don
Quote Reply
Re: Sorting a search by date In reply to
The default sort order is "ascend." "so" only needs to be defined if you're doing a descending search.

In sub query, there is the following code:
Code:
if (exists $in{'sb'}) { # Sort hits on $in{'sb'} field.
my ($sort_order, $sort_func);
$in{'so'} ? ($sort_order = $in{'so'}) : ($sort_order = "ascend");

I understand your asking, though. I thought about that when I answered the question and realized he didn't need to add the field. Smile


------------------
JPD





Quote Reply
Re: Sorting a search by date In reply to
JP,
Now I am very confused! In default.cfi I have this line...

Date => [2, 'numer', 0, 4, 4, '', ''],

And you said to add this line to my Html.pl file right?

<input type="hidden" name="Date" value="2">


I know that I have not done everything right? Cus it does not work. Where did I go wrong.

Also, just to be clear, I want the search in assending order. 1.2.3.4.5.6.7.8.9.etc.

Greg


Quote Reply
Re: Sorting a search by date In reply to
No. Not

<input type="hidden" name="Date" value="2">

but

<input type=hidden name="sb" value="2">

The sb means "sort by" -- you want the script to sort the results by field 2.


------------------
JPD





Quote Reply
Re: Sorting a search by date In reply to
JP

This little mod is not working for some reason... I have the code in place where you told me to put it. Any thoughts.

Code:
sub html_view_search {
# --------------------------------------------------------
# This page is displayed when a user requests to search the
# database for viewing.
# Note: all searches must use GET method.
#
&html_print_headers;
print qq|
<html>
<head>
<title>$html_title: Search the Database.</title>
</head>

<body bgcolor="#DDDDDD">
<form action="$db_script_url" method="GET">
<input type=hidden name="db" value="$db_setup">
<input type=hidden name="uid" value="$db_uid">

<input type=hidden name="sb" value="2">



<center>
<table border=1 bgcolor="#FFFFFF" cellpadding=0 CELLSPACING=0 width=700 align=center valign=top>
<tr><td colspan=2 bgcolor="navy">
<FONT FACE="MS Sans Serif, arial,helvetica" size=1 COLOR="#FFFFFF">
<b>$html_title: Search the Database</b>
</td></tr>
<tr><td>
<p><center><$font_title><b>
Search the Database
</b></font></center><br>
<$font>
|; &html_record_form(); print qq|
|; &html_search_options; print qq|
</font></p>
<p><center> <INPUT TYPE="SUBMIT" NAME="view_records" VALUE="View Records"> <INPUT TYPE="RESET" VALUE="Reset Form"></center></p>
|; &html_footer; print qq|
</td></tr>
</table>
</center>
</form>
</body>
</html>
|;
}

Quote Reply
Re: Sorting a search by date In reply to
I had forgotten about sub html_search_options. If you're going to define a field to sort by for every search, in html_search options you need to delete the following:

Code:
Sort By:
<SELECT NAME="sb">
<OPTION>---
~; for (my $i =0; $i <= $#db_cols; $i++) { print qq~<OPTION VALUE="$i">$db_cols[$i]</OPTION>\n~
if ($db_form_len{$db_cols[$i]} >= 0); } print qq~
</SELECT>

(The formatting above is a little different than the formatting in your script, but you should be able to find it.)


------------------
JPD





Quote Reply
Re: Sorting a search by date In reply to
This is not working yet... But I think that I completed the mods as you have told me too.

Code:

sub html_search_options {
# --------------------------------------------------------
# Search options to be displayed at the bottom of search forms.
#
print qq~
<P>
<STRONG>Search Options:</STRONG> <br>
<INPUT TYPE="CHECKBOX" NAME="ma"> Match Any
<INPUT TYPE="CHECKBOX" NAME="cs"> Match Case
<INPUT TYPE="CHECKBOX" NAME="ww"> Whole Words
<INPUT TYPE="CHECKBOX" NAME="re"> Reg. Expression<BR>
<INPUT TYPE="TEXT" NAME="keyword" SIZE=15 MAXLENGTH=255> Keyword Search <FONT SIZE=-1> (will match against all fields)</FONT><BR>
<INPUT TYPE="TEXT" NAME="mh" VALUE="$db_max_hits" SIZE=3 MAXLENGTH=3> Max. Returned Hits<BR>

Sort Order:
<SELECT NAME="so">
<OPTION VALUE="ascend">Ascending
<OPTION VALUE="descend">Descending
</SELECT><br><br>
<strong>Search Tips:</strong><br>
- use '*' to match everything in a field)<BR>
- put a '>' or '<' at the beginning to to do range searches.<BR>
~;
}
Quote Reply
Re: Sorting a search by date In reply to
Code:
# Database Definition
# --------------------------------------------------------
# Definition of your database. Format is
# field_name => ['position', 'field_type', 'form-length', 'maxlength', 'not_null', 'default', 'valid_expr']

%db_def = (
ID => [0, 'numer', 5, 8, 1, '', ''],
Title => [1, 'alpha', 40, 255, 1, '', ''],
Date => [2, 'numer', 0, 4, 4, '', ''],
Maker => [3, 'alpha', 0, 40, 1, '', ''],
Coloring => [4, 'alpha', 0, 60, 1, '', ''],
Category => [5, 'alpha', 0, 255, 1, '', ''],
Condition => [6, 'alpha', 0, 255, 1, '', ''],
Size => [7, 'alpha', 0, 40, 1, '', ''],
Description => [8, 'alpha', '40x3', 2500, 0, '', ''],
Keywords => [9, 'alpha', 40, 255, 1, '', ''],
Image => [10, 'alpha', 40, 255, 0, '', ''],
URL => [11, 'alpha', 40, 255, 1, 'http://', '^http://'],
Price => [12, 'alpha', 0, 4, 8, '', ''],
Cart => [13, 'alpha', 40, 255, 1, '', ''],
Userid => [14, 'alpha', -2, 15, 0, '', '']

);

Now you should be able to see every single change that I have made. Smile
Quote Reply
Re: Sorting a search by date In reply to
So what does it do?


------------------
JPD





Quote Reply
Re: Sorting a search by date In reply to
It sorts everything out according to the item number.
Quote Reply
Re: Sorting a search by date In reply to
Can I take a look at your database?


------------------
JPD





Quote Reply
Re: Sorting a search by date In reply to
sure, Do you want to see the default.db or the web page that is created? Or do you want to see everything?

Quote Reply
Re: Sorting a search by date In reply to
http://www.heritageantiquemaps.com/auction/orders/database/db.pl

logon with JPD
PAss with JPD
Quote Reply
Re: Sorting a search by date In reply to
It really helped to look at your database. If you'd like to change my permissions for security reasons, you can eliminate the "Add," "Delete" and "Modify" permissions for me. All I need to do is be able to view the database.

I am getting the results sorted when I do a search from the "View" link. (You have some problems with your form, though. I'll talk about them below.)

The first record has the date 167 in it, which, if that is correct is a great find! Smile

The "List All" doesn't sort, mainly because I didn't think about that and didn't give you the code for it. If you add &sb=2 to the "List All" link, you'll be able to sort those results, too.

The problem with your search form is somewhere in the "Cart" field. When I view the source, I see
Code:
<INPUT TYPE="Hidden" NAME="Cart" VALUE="<font color=Yellow>.</font color>" SIZE="0" MAXLENGTH="0">

<font color=Yellow>.</font color> will show up as a search term on all of your searches from the form and you will have a lot of problems.


------------------
JPD





Quote Reply
Re: Sorting a search by date In reply to
jp
adding &sb=2 to the url zonked them into place! But where would I put "&sb=2" so that is works all of the time?

Also, I am using the following url
Code:
http://www.heritageantiquemaps.com/auction/orders/database/db.pl?db=default&uid=default&ID=&Title=&Date=&Maker=&Coloring=---&Condition =---&Size=&Description=&Image=&URL=&Category=---&Keywords=United+States&Price=&Cart=%3Cfont+color%3DYellow%3E.%3C%2Ffont+color%3E&ww=on&keyw ord=&mh=100&sb=---&so=ascend&view_records=View+Records&sb=2

and I am having no problems with the <font color=Yellow>.</font color> cart option. I put it in there to hold a form place, so that later I can search for "<font color=Yellow>.</font color>" and replace it with what I want.

Greg
Quote Reply
Re: Sorting a search by date In reply to
I don't think your "place holder" is a good idea, but if it works, I guess it's okay.

If you want the search results for any link to be sorted by the date field, just add &sb=2 to the link.

Major suggestion -- although it will work, you don't need to include blank fields in your links. For the one you gave, I would use

Code:
http://www.heritageantiquemaps.com/auction/orders/database/db.pl?db=default&uid=default&Cart=%3Cfont+color%3DYellow%3E.%3C%2Ffont+color%3E&w w=on&view_records=1&sb=2

(I left the &Cart= in there, because it's the only search term you had.)





------------------
JPD







[This message has been edited by JPDeni (edited October 08, 1999).]
Quote Reply
Re: Sorting a search by date In reply to
JP,
Ok, I have added &sb=2 to the below section, and it seems like has done the trick! Thanks for your help.

Greg

Code:

print qq!| <A HREF="$db_script_link_url&view_search=1&sb=2">View</A> ! if ($per_view);