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?
May 13, 2013, 10:17 PM
Veteran / Moderator (18436 posts)
May 13, 2013, 10:17 PM
Post #2 of 9
Views: 11240
Hi,
Are you talking about Gossamer Links, or Gossamer Forum? (thats the forum you're in
)
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!
Are you talking about Gossamer Links, or Gossamer Forum? (thats the forum you're in

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!
May 14, 2013, 6:34 AM
Veteran / Moderator (18436 posts)
May 14, 2013, 6:34 AM
Post #4 of 9
Views: 11191
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!
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!
May 14, 2013, 1:33 PM
Novice (6 posts)
May 14, 2013, 1:33 PM
Post #5 of 9
Views: 11188
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!
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!
May 14, 2013, 6:47 PM
Enthusiast (809 posts)
May 14, 2013, 6:47 PM
Post #6 of 9
Views: 11125
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
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
May 14, 2013, 11:59 PM
Veteran / Moderator (18436 posts)
May 14, 2013, 11:59 PM
Post #7 of 9
Views: 11147
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:
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!
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!
May 16, 2013, 11:36 PM
Veteran / Moderator (18436 posts)
May 16, 2013, 11:36 PM
Post #9 of 9
Views: 11051
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!
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!