Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Global Help for Buy Now Links

Quote Reply
Global Help for Buy Now Links
Hey,

I'm using the table format and suggestiions from this thread:
http://www.gossamer-threads.com/perl/gforum/gforum.cgi?post=247397

to add a table of retailers and retailer links to display on my detailed pages. I'm using the following global:

sub {
my $id = shift;
my $retailers = $DB->table('Retailers', 'RetailerLinks')->select( { link_id_fk => $id } )->fetchall_hashref;
my $output = qq~~;
foreach my $retailer (@$retailers) {
$output .= "<span class='buylink'><a href='$retailer->{rl_url}'>Buy Now</a></span><br />";
}
return $output;
}

and placing

<%buy_now($ID)%>

in the detailed page. This works fine as long as there is only one Retailer in the retailer table. If there are 2, it shows a link on the detailed page for both retailers even though the RetailerLinks table only has a match for one Link $ID.

Any suggestions? Does this need to run through a loop or something?
Quote Reply
Re: [pshadow] Global Help for Buy Now Links In reply to
Hi,

Try this (untested =))

Code:
sub {
my $id = $_[0];
my $sth = $DB->table('Retailers', 'RetailerLinks')->select( { link_id_fk => $id } );

while (my $hit = $sth->fetchrow_hashref) {
$output .= qq|<span class='buylink'><a href='$hit->{rl_url}'>Buy Now</a></span><br />|;
}

return $output;
}

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] Global Help for Buy Now Links In reply to
No luck. Seems to do the same thing?

I first got a "Global symbol "$output" requires explicit package name at (eval 45) line 6." error. so I added

my $output = qq~~;

above
while (my $hit = $sth->fetchrow_hashref) {

So it now it shows 2 links, one for each Retailer, even if there isn't an entry for the second in the RetailerLinks table. So Buy Now from Retailer 1 and BuyNow from Retailer 2, but both having the same Retailer 1 link destination.
Quote Reply
Re: [pshadow] Global Help for Buy Now Links In reply to
Still untested... But this fixes the first error.

Code:
sub {
my $id = $_[0];
my $sth = $DB->table('Retailers', 'RetailerLinks')->select( { link_id_fk => $id } );

my $output;
while (my $hit = $sth->fetchrow_hashref) {
$output .= qq|<span class='buylink'><a
href='$hit->{rl_url}'>Buy Now</a></span><br />| if ($hit->{rl_url});
}
return $output;
}

Edited: this second change might fix the second problem.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...

Last edited by:

webmaster33: Dec 15, 2005, 12:01 PM
Quote Reply
Re: [webmaster33] Global Help for Buy Now Links In reply to
Ya, first error fixed. Second error still showing up.

What I've tried to do now is just put the Retailer Name in the RetailerLinks table, so instead of referencing Retailer "1" I just add the "Name" of the Retailer. This seems to solve the duplicate issue. Aside from having to type in the full retailer name for each URL entry, any necessary benefits for having the Retailer table separate?

As well, I tried to edit the global to take out the call to the Retailer table but it breaks if I just pull out the 'Retailers' table call in line 3.

new global: error = something about permissions in line 3?
sub {
my $id = $_[0];
my $sth = $DB->table('RetailerLinks')->select( { link_id_fk => $id } );

my $output;
while (my $hit = $sth->fetchrow_hashref) {
$output .= qq|<span class='buylink'><a href='$hit->{rl_url}'>Buy Now</a></span><br />|;
}
return $output;
}
Quote Reply
Re: [pshadow] Global Help for Buy Now Links In reply to
The only thing you need, just a condition, if it needs to display the link or not.
And the condition depends if there is link stored or not.

I supposed the link is stored in rl_url field, so the if condition on this should fix your problem.


Could you show me 2 example rows from each table?
I could decide then on which field to put the condition.

Or even better, put a
print Data::Dumper::Dumper($hit);
into the while loop to print the data.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...

Last edited by:

webmaster33: Dec 15, 2005, 1:57 PM
Quote Reply
Re: [webmaster33] Global Help for Buy Now Links In reply to
Thanks for your help.

The tables look like this:

First Table = Retailers
retail_id, retail_name
1, retailer1name
2, retailer2name

Second Table = RetailerLinks
rl_id, rl_url, retail_id_fk, link_id_fk
1, retailer1link.com/productx, 1, 920
2, retailer2link.com/productx, 2, 1009

So basically trying to map entry 1 to a specific URL on retailer1's website for link id 920 and the same for entry 2.

Currently it'll show all retailers in the Retailers table on link pages 920 and 1009. All link to the specific URL referenced in RetailerLinks table. So the global is pulling and displaying the correct link, but I can't get it to only display the link for the matching retail_id, not for each.
Quote Reply
Re: [pshadow] Global Help for Buy Now Links In reply to
Hi,

My guess would be that you don't have the foreign keys set up correctly.

You should be able to see what is going on better if you turn on debugging and load the page. Then look in your error log to find the query that selects the records from the Retailer table to see what it is actually doing.

If you post the end of your def files (the bit after the columns) of all the tables that should be linked someone should be able to help.

Laura.
The UK High Street
Quote Reply
Re: [pshadow] Global Help for Buy Now Links In reply to
Try
my $sth = $DB->table('RetailerLinks')->select( { retail_id_fk => $id } );
as the retail_id_fk is the foreign key which is common between the 2 tables.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] Global Help for Buy Now Links In reply to
From this expanation

In Reply To:

So basically trying to map entry 1 to a specific URL on retailer1's website for link id 920 and the same for entry 2.

Currently it'll show all retailers in the Retailers table on link pages 920 and 1009. All link to the specific URL referenced in RetailerLinks table. So the global is pulling and displaying the correct link, but I can't get it to only display the link for the matching retail_id, not for each.[/quote]

I think that the link is correct in each case - it's just that the row out of the RetailerLinks table is being linked to both retailers - that is why I don't think the foreign key is set up between the Retailers and the RetailerLinks table.

But maybe I haven't understood...