Gossamer Forum
Home : Products : Gossamer Links : Discussions :

loop problem in standalone script

Quote Reply
loop problem in standalone script
Hi, I'd really appreciate some help here.


i am considering modify a cool page or what is new page. basically i want links listed on the page been printed
through the way of loop of i could use tag <%even%>


here is the orignal code




sub main
{ #--------------------------------------------------- #
if (!$USER)
{
my $url = $IN->escape ($IN->url ( absolute => 1, query_string => 1 ));
print $IN->redirect ( $CFG->{db_cgi_url} . "/user.cgi?url=$url" );
return;
}

else
{
featured();
}

}


# you are now logged in and user info is in $USER.

sub featured {
#---------------------------------------------------
#
my $pageNum = $IN->param('nh') || 1;
my $linksPP = 5;
my $start = $linksPP * $pageNum - $linksPP;
$start = ($pageNum < 2) ? 0 : $start;

my ($sth,$tab,$output);

$tab = $DB->table('Links');
$tab->select_options('ORDER BY Title', 'LIMIT ' . $linksPP . ' OFFSET ' . $start);
$sth = $tab->select( { isValidated => 'Yes' } );
my $hits = $tab->hits;

while (my $rec = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display('link', $rec);
}

my $tags;
$tags->{'paging'}->{'url'} = $CFG->{db_cgi_url} . "/admin/linktest/featured.cgi";
$tags->{'paging'}->{'num_hits'} = $hits;
$tags->{'paging'}->{'max_hits'} = $linksPP;
$tags->{'paging'}->{'current_page'} = $pageNum;
$tags->{'output'} = $output;

print $IN->header();
print Links::SiteHTML::display('detail', $tags);
}


1;
Quote Reply
Re: [linkpro] loop problem in standalone script In reply to
Then i slightly make some change on the code hope it could produce a right loop for me


sub main
{ #--------------------------------------------------- #
if (!$USER)
{
my $url = $IN->escape ($IN->url ( absolute => 1, query_string => 1 ));
print $IN->redirect ( $CFG->{db_cgi_url} . "/user.cgi?url=$url" );
return;
}

else
{
featured();
}

}


# you are now logged in and user info is in $USER.

sub featured {
#---------------------------------------------------
#
my $pageNum = $IN->param('nh') || 1;
my $linksPP = 5;
my $start = $linksPP * $pageNum - $linksPP;
$start = ($pageNum < 2) ? 0 : $start;

my ($sth,$tab,$output,@output);

$tab = $DB->table('Links');
$tab->select_options('ORDER BY Title', 'LIMIT ' . $linksPP . ' OFFSET ' . $start);
$sth = $tab->select( { isValidated => 'Yes' } );
my $hits = $tab->hits;

while (my $rec = $sth->fetchrow_hashref) {
#####$output .= Links::SiteHTML::display('link', $rec);
#################################################################
push (@output, $rec);
#################################################################

}

my $tags;
$tags->{'paging'}->{'url'} = $CFG->{db_cgi_url} . "/admin/linktest/featured.cgi";
$tags->{'paging'}->{'num_hits'} = $hits;
$tags->{'paging'}->{'max_hits'} = $linksPP;
$tags->{'paging'}->{'current_page'} = $pageNum;
####$tags->{'output'} = $output;

#################################################################

$tags->{'output'} = @output;
#################################################################

print $IN->header();
print Links::SiteHTML::display('detail', $tags);
}




then i call it in detail.html like this


blah blah blah
<%loop output%>
<%include link.html%>
<%endloop%>





the link.html looks like this


<%id%>
<%row_num%> <%if even%>this even record <%else%>this is non even record <%endif%>

unfortunately i got error. it seems that <%even%>and <%row_num%> were unknow tags





did it miss something ????
Any assistance would be very much appreciated,


Cheers!

Clifts
Quote Reply
Re: [linkpro] loop problem in standalone script In reply to
I think you actually want:

Code:
$tags->{'output'} = \@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: [linkpro] loop problem in standalone script In reply to
Worked like a charm!

Thanks Andy . you are the best