Gossamer Forum
Home : Products : DBMan : Customization :

Small question on default sorting

Quote Reply
Small question on default sorting
I am using JPDeni's relational mod. By default, Show All command returns all records sorted against DateAdded field in ascending order. It seems there is a way to define the default sorting order (I need descending order), but I could not find that spot in either .cfg or .format file. I don't want to use "sb=x&so=ascend" in the hyperlink for Show All command, since all my database share a single html_page_top sub and the DateAdded field does not have the same field number in them. Any help would be greatly appreciated.

Long

Quote Reply
Re: Small question on default sorting In reply to
In db.cgi, change the following line:

$in{'so'} ? ($sort_order = $in{'so'}) : ($sort_order = "ascend");

to:

$in{'so'} ? ($sort_order = $in{'so'}) : ($sort_order = "descend");

Its in the section of code:
Code:

# Sort the array @hits in order if we are meant to sort.
if (exists $in{'sb'}) { # Sort hits on $in{'sb'} field.
my ($sort_order, $sort_func);
$in{'so'} ? ($sort_order = $in{'so'}) : ($sort_order = "ascend");
$sort_func = "$db_sort{$db_cols[$in{'sb'}]}_$sort_order";

foreach $hit (sort $sort_func (keys %sortby)) {
$first = ($hit * $#db_cols) + $hit; $last = ($hit * $#db_cols) + $#db_cols + $hit;
push (@sortedhits, @hits[$first .. $last]);
}
@hits = @sortedhits;
}
That should do it.

- Mark

Astro-Boy!!
http://www.zip.com.au/~astroboy/
Quote Reply
Re: Small question on default sorting In reply to
Hi, Mark

Thanks for reply. I changed the word from "ascend" to "descend", there is no difference. Show All command still lists records from oldest to newest. What else could be wrong?

Long

Quote Reply
Re: Small question on default sorting In reply to
You're right, sorry, my fault. Crazy

Ok, here's what's happening. DBMan only ever sorts the results if it recieves &sb=X in the link

ie: (from db.cgi)
if (exists $in{'sb'}) {
... sort the results ...
}


So, unless we hack a default into db.cgi, you'll have to pass it in via the link. It can be hacked, but I haven't really fiddled with 'sub query' yet. I imagine it could'nt be hard though...

Shall look into it
(unless someone beats me to it Smile)

- Mark

Astro-Boy!!
http://www.zip.com.au/~astroboy/
Quote Reply
Re: Small question on default sorting In reply to
in sub query after:

local (%sortby);

add lines:

$in{'sb'} = ''; # no value but here
$in{'so'} = 'descend'; # actual entries first

Note: This code will change all your searches and results may depend on other search field (which can also be set to default as shown).

sab, DBMan Junior

Quote Reply
Re: Small question on default sorting In reply to
This will certainly work, but will override any sort switches past in by the query string. ie: putting &sb=ascend in the link will no longer work.

A better way to write it would be:

$in{'sb'} = (($in{'sb'}) ? $in{'sb'} : '' );
$in{'so'} = (($in{'so'}) ? $in{'so'} : 'descend');

This way, if parameters are passed in, they will sitll affect the sorting.

Cheers,

- Mark

Astro-Boy!!
http://www.zip.com.au/~astroboy/
Quote Reply
Re: Small question on default sorting In reply to
Yes -sorry. In my DBMan posted query lines are in a separate db.cgi for public users only. They can not choose between descend/ascend. I separated an absolute .cgi (included by SSI) to get only some fields in this 'descend' way.

sab, DBMan Junior

Quote Reply
Re: Small question on default sorting In reply to
Thank you both for replying. However, it still doesn't work.

After
local (%sortby);

I add

$in{'sb'} = (($in{'sb'}) ? $in{'sb'} : '' );
$in{'so'} = (($in{'so'}) ? $in{'so'} : 'descend');

These lines make no difference when I use &view_records=1&ItemID=*, records are still in ascending order. I tried to change the word "descend" to "ascend",no changes happen either.

Long

Quote Reply
Re: Small question on default sorting In reply to
Are you sorting on the right field?

eg, If "date" is field 3, you would put 3 in place of Field Number:
$in{'sb'} = (($in{'sb'}) ? $in{'sb'} : 'Field Number' );

- Mark


Astro-Boy!!
http://www.zip.com.au/~astroboy/
Quote Reply
Re: Small question on default sorting In reply to
Now it makes sense and works. I use ItemID as the sorting field instead of DateAdded, since ItemID has a fixed field number among all my db.

Thank you all for helping.

Long