Gossamer Forum
Home : Products : DBMan : Installation :

Sorting question

Quote Reply
Sorting question
Hello,

DBman currently has this two sorting functions:

sub alpha_ascend { lc($sortby{$a}) cmp lc ($sortby{$b}) }
sub alpha_descend { lc($sortby{$b}) cmp lc ($sortby{$a}) }

which sorts an alphanumeric string in either ascending or descending order. This is fine but, how can I sort the following strings "ONLINE, CLOSED, ANSWERED" so that

ONLINE is first
ANSWERED is second
CLOSED is third

Ascending would give me ANSWERED, CLOSED, ONLINE and descending the opposite so I need to figure out some sort of sort function that does the trick for me...

Thanks
-JO
Quote Reply
Re: Sorting question In reply to
You can do it, but you'll have to create a different type of field.

Are these options in a select field, radio fields or entered in a text field?


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





Quote Reply
Re: Sorting question In reply to
Hi JPD,

What I am trying to sort is a normal alpha field called "Status". When I go to the viewing form, I want to be able to sort the records based on Status in that particular order.

Cheers
-JO
Quote Reply
Re: Sorting question In reply to
I understand. But the only way you can get it to sort is to "translate" your names into either numbers or other letters that will sort the way you want them to -- so that

ONLINE = 1
ANSWERED = 2
CLOSED = 3

(you could also use "a, b and c" if you wanted)

Then the script can sort by the "translation" instead of the actual word. It can still print out the word, even though the word isn't in your database.

What I want to give you is a way that the script will automatically enter the number when you select the word in either a select field or a radio field.

I suppose it would be possible to work out some other way to do it, but it would be much more complicated.

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





Quote Reply
Re: Sorting question In reply to
The point is that you don't need to do that. You can use the current sort routines as they are, and have your data type for the Status field as "numer." You can create a radio button that looks like

<INPUT TYPE="RADIO" NAME="Status" VALUE="1"> ONLINE
<INPUT TYPE="RADIO" NAME="Status" VALUE="2"> ANSWERED
<INPUT TYPE="RADIO" NAME="Status" VALUE="3"> CLOSED

Or, you can have a select field that looks like
<SELECT NAME="Status"><OPTION>---
<OPTION VALUE="1">ONLINE
<OPTION VALUE="2">ANSWERED
<OPTION VALUE="3">CLOSED</SELECT>

I can give you the subroutine to build these fields, but I'd rather only type in one. If you'll tell me whether you use a radio field or a select field to set the status of a record, I'll be happy to give you the code you need.


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





Quote Reply
Re: Sorting question In reply to
Hi JPD,

That is kind of what I did but I was hoping there was some other way since assigning a value to every status forces me to go to the actual sub every time a new status is added/removed. This is not very often but...

Cheers
-JO

PS: for those interested, I created a new type of field (changed field Status from alpha to status) and then added two new sort routines (status_descend and status_ascend).
I then replaced the status strings (ONLINE...) by numbers and did the compare.

Quote Reply
Re: Sorting question In reply to
Hi,

Thanks for replying again...

Would something like this

<A HREF=$db_script_url/db.pl?$query_string&sb=5&so=descend >

work with what you suggested (5 is the Status field)?

Cheers
-JO
Quote Reply
Re: Sorting question In reply to
I don't know. I've never used $query_string.



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