Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Sponsor Global

Quote Reply
Sponsor Global
I want to create a new column called sponsors in links properties and then have any links that are checked be listed on all pages in my site. Is there already a global that I could use to get these results? Keep in mind that I'm a complete newby and can't modify anything:

Thanks,

Craven
Quote Reply
Re: [craven32] Sponsor Global In reply to
Create the field and then create a new template called link_sponsored.html (just save link.html as link_sponsored.html). Then you can modify this new template to get the sponsored listing looking how you want.

sub {
# Displays the sponsored links on every page.
my ($output,$sth,$link);
my $search_db = $DB->table('Links');
$search_db->select_options ("ORDER BY rand()");
$sth = $search_db->select ( { sponsors => 'Yes', isValidated => 'Yes'});
while ($link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display ('link_sponsored', $link);
}
return $output;
}
Quote Reply
Re: [afinlr] Sponsor Global In reply to
I tried this out but got the following error.

A fatal error has occured:
Can't call method "fetchrow_hashref" on an undefined value at (eval 6) line 7.


Please enable debugging in setup for more details.

Did I do something wrong?
Quote Reply
Re: [craven32] Sponsor Global In reply to
Have you got a field called sponsors in your Links table?
Quote Reply
Re: [afinlr] Sponsor Global In reply to
Yes, I added the field sponsors. I tried several different ways, first as Enum then as text.
Quote Reply
Re: [craven32] Sponsor Global In reply to
Should I use a certain type of Column Index? Text, Enum, Char? What values should be entered? Sorry but I'm clueless!

Craven
Quote Reply
Re: [craven32] Sponsor Global In reply to
Can you just go to admin->setup->miscellaneous and turn debugging to 1. Then when you get the error message, look down the page to system information - this should give you a more helpful error message after GT::SQL::error
Quote Reply
Re: [afinlr] Sponsor Global In reply to
What does this mean?

GT::SQL::error = Failed to execute query: 'SELECT * FROM lsql_Links WHERE isValidated = ? AND Sponsor = ?
ORDER BY rand()' Reason: You have an error in your SQL syntax near 'rand()' at line 2
Quote Reply
Re: [craven32] Sponsor Global In reply to
Just take out that line that has the rand() in it - its not necessary.
Quote Reply
Re: [afinlr] Sponsor Global In reply to
Wink That was it! Thanks so much for the help!

Craven
Quote Reply
Re: [afinlr] Sponsor Global In reply to
Would it be much harder to limit the number of sponsors to 10 and then randomly select the sponsors?

Craven
Quote Reply
Re: [craven32] Sponsor Global In reply to
This is how I would do it:

$search_db->select_options ("ORDER BY rand()", "LIMIT 10");

The rand() function only works on new versions of mysql I think which I assume is why it caused a problem. I think there are alternative suggestions on the forum for older versions of mysql or different databases.
Quote Reply
Re: [craven32] Sponsor Global In reply to
Here's a starting point:

http://www.gossamer-threads.com/...i?post=122626#122626
Quote Reply
Re: [afinlr] Sponsor Global In reply to
I'm contacting my host to see if they will update to a newer version of MySQL to see if this helps. Thanks for all the help!

Craven
Quote Reply
Re: [craven32] Sponsor Global In reply to
Well my host upgraded and now the random function works great!

Now that it works I have another question. How could I get the Sponsor links to display by category?

Craven
Quote Reply
Re: [craven32] Sponsor Global In reply to
Need a bit more info - do you want to just display the category with the link or have different sponsored links showing depending on which category you are in; or something else?
Quote Reply
Re: [afinlr] Sponsor Global In reply to
I want different sponsored links showing depending on which category I'm in. Sorry for not being more clear!

Thanks,

Craven
Quote Reply
Re: [craven32] Sponsor Global In reply to
This is untested:

sub {
# Displays the sponsored links on every page.
my ($output,$sth,$link,$cond);
my $tags=shift;
my $catid = $tags->{catid};
my $search_db = $DB->table('Links','CatLinks');
$search_db->select_options ("ORDER BY rand()");
if ($catid){
my $cat_db = $DB->table('Category');
my $all_ids = $cat_db->children($cat_id);
push @$all_ids, $cat_id;
$cond = GT::SQL::Condition->new('sponsors', '=', 'Yes', 'isValidated','=','Yes', 'CategoryID', 'IN', $all_ids);
}
else {
$cond = GT::SQL::Condition->new('sponsors', '=', 'Yes', 'isValidated','=','Yes');
}
$sth = $search_db->select ($cond);
while ($link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display ('link_sponsored', $link);
}
return $output;
}
Quote Reply
Re: [afinlr] Sponsor Global In reply to
Just tried it out but I get the following error.

Unable to compile 'cat_sponsor':

I'm trying some small changes to see if I can figure it out! I'm not holding my breath thoguhSly

Craven
Quote Reply
Re: [craven32] Sponsor Global In reply to
At a first glance - one of the $catids has an underscore which needs removing.

Unfortunately don't have time to test it just at the moment.

Edit - make that two of the $cat_ids!

Last edited by:

afinlr: Nov 15, 2003, 8:35 AM
Quote Reply
Re: [afinlr] Sponsor Global In reply to
I changed the cat_id to catid and no longer get an error! But it is displaying all sponsors not just from the category I'm browsing:(

Craven
Quote Reply
Re: [craven32] Sponsor Global In reply to
Ah, I guessed that there was a catid tag on the category pages - it seems to be category_id. Can you change this line

my $catid = $tags->{catid};

to

my $catid = $tags->{'category_id'};
Quote Reply
Re: [afinlr] Sponsor Global In reply to
WOW! This works great. You are the best! Is gossamer paying you? They should be!

Thanks,

Craven
Quote Reply
Re: [craven32] Sponsor Global In reply to
I wish Wink.

These things are always much easier when you've done similar things before - and it helps me to get things done more quickly on my site when I keep on top of the code.