Gossamer Forum
Home : Products : DBMan : Discussions :

sort on dynamic field

Quote Reply
sort on dynamic field
Hi,

went through JPDeni's FAQ and this forum as well, can't seem to find any data on sorting on a dynamically generated field. should be easy, but it's eluding me due to the "sb=" system which is not going to work since the field doesn't actually exist. here's the concept:

$rec{'students'};

$rec{'seats'};

$openseats=$rec{'seats'}-$rec{'students'};

$openseats is a column of numbers in the output table. I would like to be able to sort on that with a link, so students can see the classes that are wide open, and those that are filling up.

how can I sort on that column?
Quote Reply
Re: [shawnchittle] sort on dynamic field In reply to
If you intend to sort on the SAME dynamic field each time, then you should be able to hardcode the sort. That is edit the db.cgi to always sort the way you want. You can also create your own sub routine to do the sort only when requested, instead of all the time.


Below in direct from db.cgi:

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;
}

I suspect that you could modify this portion to sort on the dynamic field. Probably just assign a new value to $in{'sb'}.

Good luck.
Quote Reply
Re: [joematt] sort on dynamic field In reply to
Not a bad lead at all! I will try that. In the meantime, if anyone has any bright ideas, let me know. I seem to have stumped people with this one, very little activity! :-)
Quote Reply
Re: [shawnchittle] sort on dynamic field In reply to
I hope you understand how to create a new sub_routine and call it from a link or a search page. Usually I start by copying an existing sub, renaming it, start hacking a little at a time, test as you go.

I'm sure there is some general information on creating new sub's at LoisC's site.