Gossamer Forum
Quote Reply
Should it be in a Loop
I would like to show a header only if there is any links from this sub.
Does this need to be in a loop, if it does how do you do it.


sub {
my ($id,$search_db,$output,$sth,$link);
$id = shift;
$search_db = $DB->table('Links','CatLinks');
$search_db->select_options ("ORDER BY rand()");
$sth = $search_db->select ({xxx => 'Yes', isValidated => 'Yes', CategoryID=>$id});
while ($link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display ('xxx', $link);
}
return $output;
}

Thanks everyone for all your help!
Quote Reply
Re: [rascal] Should it be in a Loop In reply to
Try;

Code:
sub {

my ($id,$search_db,$output,$sth,$link,@links);
$id = shift;
$search_db = $DB->table('Links','CatLinks');
$search_db->select_options ("ORDER BY rand()") || return $GT::SQL::error;
$sth = $search_db->select ({xxx => 'Yes', isValidated => 'Yes', CategoryID=>$id}) || return $GT::SQL::error;
while ($link = $sth->fetchrow_hashref) {
push @links, $link;
}
return { rand_links_loop => \@links };
}

..and then you should be able to call it with;

Code:
<%global_name($ID)%>

<%if rand_links_loop%>
<h1>Random Links</h1>
<%loop rand_links_loop%>
<include link.html%>
<%endloop%>
<%endif%>

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!

Last edited by:

Andy: Mar 14, 2005, 11:21 PM
Quote Reply
Re: [Andy] Should it be in a Loop In reply to
Andy,
Thanks for your help!


I tryed the above code, it shows the header only, no links.

(It shows the header all the time)
Quote Reply
Re: [rascal] Should it be in a Loop In reply to
Mmm... how does the modified global work now? I've added some $GT::SQL::error calls in, so we can try and see whats going on :)

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] Should it be in a Loop In reply to
Not receiving any errors with your modified code.

Doing same exact thing.

The code in my first post worked fine, but the header was there when no links were available.

Any other thoughts on this Andy.
Quote Reply
Re: [rascal] Should it be in a Loop In reply to
In Reply To:
Not receiving any errors with your modified code.

Doing same exact thing.

The code in my first post worked fine, but the header was there when no links were available.

Any other thoughts on this Andy.

Correction....

Error in your code, now I get the links, but I'm still getting the header, when I have no links to display.

You had: <include link.html%>

Corrected to: <%include link.html%>

Quote Reply
Re: [rascal] Should it be in a Loop In reply to
heheh,... don't blame that on me... you copy and pasted Sly

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] Should it be in a Loop In reply to
No blame intended... Cool still can't figure out why the if statement won't work.
Quote Reply
Re: [rascal] Should it be in a Loop In reply to
If you put a <%GT::Template::dump%> tag in the template, what does the "rand_links_loop" tag show? undef?

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] Should it be in a Loop In reply to
The link info is showing, if a link is not available, Var. shows nothing.

The links are displaying when they should, it's the header that's always there.

I guess it's time to panic!!!!
Quote Reply
Re: [rascal] Should it be in a Loop In reply to
Hello,

Still have not figured out this problem. Does anyone have a solution?
Quote Reply
Re: [Andy] Should it be in a Loop In reply to
That should be:
Code:
<%if rand_links_loop.length%>
You also might want to change:
Code:
push@links, $link;
to (you might need to require Links::SiteHTML):
Code:
$link = Links::SiteHTML::tags('link', $link);
push@links, $link;
To properly format the link data to make it suitable for use by link.html.

Adrian