Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Re: [aus_dave] Global to list links without reviews

Quote Reply
Re: [aus_dave] Global to list links without reviews In reply to
Hi,

The easiest way, would be to make a new .cgi script - say "update_reviews.cgi" in the admin folder, with the following:
Code:
#!/usr/local/bin/perl

use strict;
use lib '/path/to/admin';
use Links qw/$DB $IN $USER $CFG/;
use GT::Mail;
use CGI::Carp qw(fatalsToBrowser);
use Links::Plugins;
use Links;

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

my $sth = $DB->table('Links')->select( ['ID'] ) || die $GT::SQL::error;

while (my $id = $sth->fetchrow) {
my $cnt = $DB->table('Reviews')->count( { Review_LinkID => $id } ) || 0;
$DB->table('Links')->update( { ReviewCount => $cnt }, { ID => $id } ) || die $GT::SQL::error;
print qq|Updated linkID $id with $cnt reviews \n|;
}

Then, setup a cronjob to run each day.

perl /path/to/admin/update_reviews.cgi

Then, be sure to add a new field in the "Links" table via:

Database > Links > Properties > Add Column.

Name: ReviewCount
Type: INT

Then, run this script manually (via SSH), and check to see if the links have had their new ReviewCount field updated correctly.

Then, this global should grab the results you want:

Code:
sub {
# Displays 20 random links with no review
my ($output,$sth,$link);
my $search_db = $DB->table('Links');
$search_db->select_options ('ORDER BY RAND()', 'LIMIT 20');
$sth = $search_db->select ( { isValidated => 'Yes', ReviewCount => '0' } );
while ($link = $sth->fetchrow_hashref) {
if (length $link->{Title} > 26) {
$link->{Titleshort} = substr($link->{Title}, 0, 25) . '...';
}
$output .= Links::SiteHTML::display ('templatename', $link);
}
return $output;
}

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!
Subject Author Views Date
Thread Global to list links without reviews aus_dave 4470 May 17, 2007, 4:03 AM
Thread Re: [aus_dave] Global to list links without reviews
Andy 4363 May 17, 2007, 6:55 AM
Thread Re: [Andy] Global to list links without reviews
aus_dave 4365 May 17, 2007, 3:01 PM
Thread Re: [aus_dave] Global to list links without reviews
Andy 4351 May 19, 2007, 2:50 AM
Thread Re: [Andy] Global to list links without reviews
aus_dave 4348 May 19, 2007, 4:14 AM
Thread Re: [aus_dave] Global to list links without reviews
Andy 4340 May 22, 2007, 1:23 AM
Thread Re: [Andy] Global to list links without reviews
aus_dave 4286 May 31, 2007, 7:21 PM
Post Re: [aus_dave] Global to list links without reviews
Andy 4299 Jun 1, 2007, 3:09 AM