Gossamer Forum
Home : Products : DBMan : Installation :

Sort By:

Quote Reply
Sort By:
Hi,

I would like to perform the following task.

When a user sees the search results, it will basically be a table. On the top, there will be a row like Name, Company, Regular Price, Our Price, etc.. Under this row will be the actual rows with the search results. Something like this Support Forum looks like.

This is what I would like to do. I want to make the top row into links. So Name, Company, List Price, Our Price, will all be links. The links which I want it to be is sb=the fields where it's located. I think You know where I'm getting to from here. So let's say the user does a search, they get 10 results sorted by Name. Now let's say the user doesn't want to sort it by name but rather by Company. Instead of going back to the search form, doing a search again, and this time selecting Company from the drop down menu. The user simply clicks on Company on the top row, and the page will reload with the sorting set to company.

I don't think this is such a difficult task to achieve, I just hope I'm right. Please tell me how I can do this.

------------------
JFrost





Quote Reply
Re: Sort By: In reply to
It's a little more complicated than you think! Smile

You'd have to reprint all the original search fields in your links, in additon to the 'sb' option. Hmmmm. I'm thinking.

Code:
$i = 0;
$search = "";
foreach $column (@db_cols) {
if ($in{$column}){
unless ($in{$column} eq "*") {
$in{$column} =~ s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/eg;
}
$search .= "&$column=$in{'column'}";
}
$i++;
}

Then, when you print out your links, use

<a href="$db_script_link_url$search&sb=#&view_records=1">

replacing the # with the number of the field you want to sort by.

This is completely untested.


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




[This message has been edited by JPDeni (edited March 07, 1999).]
Quote Reply
Re: Sort By: In reply to
Hi,

Again, thank you for your help.

The first thing which is good, is that I got no error message when adding this to the html.pl file.

The second thing which is not good, that this is not working. Meaning, I try doing the List All, I get the results fine, but the link which I set for the sb= is not working. I get this as the link. http://www.domain.com/cgi-bin/dbman/db.cgi?db=default&uid=&Item=&sb=1&view_records=1.
As you can see the Item field is blank, where there should be a *.

I hope I am not making it too difficult for you, but I know you always love a good challenge.


------------------
JFrost





Quote Reply
Re: Sort By: In reply to
I hadn't thought about "*" searches.

Rather than copy the whole routine over again, I just made changes in the previous code. The changes are in bold print.

This will not work if you have fields that are "field-gt" or "field-lt" searches.

Did you try it out with actually searching for something specific? I'd be interested to see how that worked.

Also, is there a chance that people will be entering a phrase as a search term, or will they always only be entering one word? If it's only one word (with no puncuation or other symbols) it can be a little easier.

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


Quote Reply
Re: Sort By: In reply to
Hi,

Actually my only search field is "keyword", and if you say this will be easier, I would love to know how. So far it hasn't been working out.

By the way, does it make a difference where I put it on the html.pl file. Until now I put it under "my ($maxhits);" by html_view_success

------------------
JFrost





Quote Reply
Re: Sort By: In reply to
Your only search is keyword? That makes things a whole lot easier -- and different from what I gave you.

Code:
if ($in{'keyword'})
unless ($in{'keyword'} eq "*") {
$in{'keyword'} =~ s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/eg;
}
$search = "&keyword=$in{'keyword'}";
}
elsif ($in{$db_key} eq "*") {
$search = "&$db_key=*";
}

If you only have one-word searches in the keyword field, you can make it easier still --

Code:
if ($in{'keyword'})
$search = "&keyword=$in{'keyword'}";
}
elsif ($in{$db_key} eq "*") {
$search = "&$db_key=*";
}

This will not work, however, if there are any spaces in the search term, or any characters other than letters and numbers.


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


Quote Reply
Re: Sort By: In reply to
Hi,

I want to thank you again for your wonderful help, it works fine now.

You seemed to have forgotten a small right bracket after "if ($in{'keyword'})" but I had no problem finding it. I'm really glad you left it out, and I ended finding it. I am learning everyday because of this great forum.

JPDeni You Are The Man (Or Women)

------------------
JFrost





Quote Reply
Re: Sort By: In reply to
Yep, those brackets sure get in the way. I still forget things like semi-colons, too.

I'm sure glad it worked, though. And that you're learning something as we go along. I always like to see folks that can start to see what's going on.

Quote:
JPDeni You Are The Man (Or Women)

Woman Smile



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