Gossamer Forum
Quote Reply
Sort By Functionality
I currently have the ability to use the sort by functionality using the sb tag in the url for the search results. I wanted to include the average review for the link as part of the sorting capabilities. Since the current system uses the sb function by sorting with the field name in the db, it makes it hard to sort by the average review, which is all stored in a separate table. Is there a way to get the average review sort by functionality to work?
Quote Reply
Re: [patricktarget] Sort By Functionality In reply to
Hi,

Are you talking about Gossamer Links, or Gossamer Forum? (thats the forum you're in Whistle)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Sort By Functionality In reply to
Oops. I have posted it in the Gossamer Links forum.
Quote Reply
Re: [patricktarget] Sort By Functionality In reply to
Hi,

No problem.

The simplest way to sort by an average review score, is to have a script run once a night that goes through each link, gets the average rating... and then stores it in the Links table. That way you can just sort by it.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Sort By Functionality In reply to
Thanks for the help Andy.

I have a couple of more questions...

1. For some reason, when I add the &sb=Title or &sb=Title DESC to the url for the category pages on glinks, it doesn't sort the items as it should. Is there something that I am missing?

2. Related to my previous question, I noticed a field called Rating in the database table. Is there any functionality that uses that field for the data? I was thinking of making it so that it would update the rating number every time a new review has been approved and then just sort by that field.

Thanks!
Quote Reply
Re: [patricktarget] Sort By Functionality In reply to
Hi,

For 1), To use &sb=Title&so=desc should be working.

For 2), the Rating is used for link, at least in rate.cgi. So, can add another field for your purpose.

Hope that helps!

Cheers,

Dat

Programming and creating plugins and templates
Blog
Quote Reply
Re: [patricktarget] Sort By Functionality In reply to
Hi,

1) Using sb in category pages won't work. You need to update the category sort order defined in Setup > Build Options. sb is only effeective for things like review.cgi / search.cgi

2) As Tandat said, this is used by the rate.cgi system. I would leave that alone. Just add a new one called "ReviewRating" or something (as a FLOAT)...then make a script to simply go through each link and get the average rating nightly:

Code:
#!/usr/local/bin/perl

use strict;
use CGI::Carp qw(fatalsToBrowser);
use lib '/path/to/admin';
use Links qw/$PLG $IN $DB/;

local $SIG{__DIE__} = \&Links::fatal;

Links::init('/path/to/admin');

my $Reviews = $DB->table("Reviews");
my $Links = $DB->table("Links");
my $sth = $Links->select( ['ID'], { isValidated => "Yes" } );
while (my $id = $sth->fetchrow) {
$Links->update( { ReviewRating => $Reviews->select( ['AVG(Review_Rating)'], { Review_LinkID => $id } )->fetchrow }, { ID => $id }) || die $GT::SQL::error;
}

Untested, but should work =)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Sort By Functionality In reply to
Hi Andy,

Is there anyway to use the sort functionality in the category page in the url? I have a sort by dropdown on the page and it would be ideal to have this work through the url. They can sort by the title and others. Is this possible?
Quote Reply
Re: [patricktarget] Sort By Functionality In reply to
Hi,

I *think* you can sort categories by doing:

page.cgi?g=Category_Name/Foo_Bar;sb=The_Field;so=ASC

Hope that helps

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!