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

how to translated to loop

Quote Reply
how to translated to loop
 now i have a route

sub {
my $ordernumber= '4646x';
# Displays links table join
my ($output,$sth,$orderlistxx,$orderlistxx1);
my $search_db = $DB->table('orderlistxx','orderlistxx1');
$sth = $search_db->select ( { orderidtrackm => $ordernumber});
while ($orderlistxx = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display ('8orderlistxx', $orderlistxx);
}
return $output;
}

it works well


now i want to use
<%row_num%> - a counter for what row is being looped, starts at 1.
<%rownum%> - an alias for <%row_num%>
<%first%> - boolean value that is true if this is the first row, false otherwise.
<%last%> - boolean value that is true if this is the last row, false otherwise.
<%inner%> - boolean value that is true if this is not first and not last.
<%even%> - boolean value is true if row_num is even.
<%odd%> - boolean value is true if row_num is odd.

which is only available to loop


so i try to conver the route to loop

sub {
my $ordernumber= '4646x';
# Displays links table join
my ($output,$sth,$orderlistxx);
my $search_db = $DB->table('orderlistxx','orderlistxx1');
$sth = $search_db->select ( { orderidtrackm => $ordernumber});
while ($orderlistxx = $sth->fetchrow_hashref) {
push @orderlistxx, $orderlistxx;
}
return {
8leftjoinloop => \@orderlistxx }
}


however it seems i something wrong with it as i get nother when i
put <%if first%>white<%else%>silver<%endif%>

there should be something wrong with the sub


i wonder anyone here could help me?


Thanks in advance
Quote Reply
Re: [courierb] how to translated to loop In reply to
Hi,

Mmm.. not sure, that should be ok. You could always try something like:
Code:
<%set counter = 0%>
<%loop 8leftjoinloop%>
<%set counter += 0%>
<%if counter == 1%>its the first row<%endif%>
<%if counter == 8leftjoinloop.length%>its the last row<%endif%>
do whatever you want here
<%endloop%>

Totally untested - but should work :)

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] how to translated to loop In reply to
andy


thank you for you reply


i have put it have a try

it is failed with nothing returned

i believe it is somehint wrong with sub. as i have done it sucessufully with other loop sub. while it is failed in this case.
Quote Reply
Re: [courierb] how to translated to loop In reply to
Hi,

Well, thats pretty much how I would have coded it :)

One thing I noticed, is you declared $orderlistxx , but needed @orderlistxx. Try the below one, and see if that works.

Code:
sub {
my $ordernumber= '4646x';
# Displays links table join
my @orderlistxx;
my $search_db = $DB->table('orderlistxx','orderlistxx1');
my $sth = $search_db->select ( { orderidtrackm => $ordernumber}) || die $GT::SQL::error;
while ($orderlistxx = $sth->fetchrow_hashref) {
push @orderlistxx, $orderlistxx;
}
return { 8leftjoinloop => \@orderlistxx }
}

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: [courierb] how to translated to loop In reply to
andy

it produce nothing.
Quote Reply
Re: [courierb] how to translated to loop In reply to
Does the global give any error?

Also, what if you have:

Code:
<%DUMP 8leftjoinloop%>

?

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] how to translated to loop In reply to
now i get


Dumped value of '8leftjoinloop':
undef;
Quote Reply
Re: [courierb] how to translated to loop In reply to
Ok, but do you get anything from the global? i.e an "Unable to compile..." error messsage? (normally shows wherever you are calling it)

BTW, can you show me EXACTLY how you are calling this in the template?

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] how to translated to loop In reply to
Dumped value of '8tablejointest': sub { () };
Quote Reply
Re: [courierb] how to translated to loop In reply to
i am calling it by



<%set counter = 0%>
<%loop 8tableleftjoinloop%>
<%set counter += 0%>
<%if counter == 1%>its the first row<%endif%> <%if counter == 8tableleftjoinloop.length%>its the last row<%endif%> do whatever you want here <%endloop%>
<div id="ocwrapper" class="clear">
Quote Reply
Re: [courierb] how to translated to loop In reply to
<%set counter = 0%>
<%loop 8leftjoinloop%>
<%set counter += 0%>
<%if counter == 1%>its the first row<%endif%> <%if counter == 8ftjoinloop.length%>its the last row<%endif%> do whatever you want here <%endloop%>
<div id="ocwrapper" class="clear">
Quote Reply
Re: [courierb] how to translated to loop In reply to
Yeah, but whats the name of the global? You need to call that first!

i.e

Code:
<%8tableleftjoinloop_gen%> <%-- this is what makes the loop --%>

...then:

Code:
<%set counter = 0%>
<%loop 8tableleftjoinloop%>
<%set counter += 0%>
<%if counter == 1%>its the first row<%endif%> <%if counter == 8tableleftjoinloop.length%>its the last row<%endif%> do whatever you want here <%endloop%>
<div id="ocwrapper" class="clear">

..and then rename the global to "8tableleftjoinloop_gen".

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: [courierb] how to translated to loop In reply to
the global is

sub { my $ordernumber= '4646x'; # Displays links table join my @orderlistxx;
my $search_db = $DB->table('orderlistxx','orderlistxx1');
my $sth = $search_db->select ( { orderidtrackm => $ordernumber}) || die $GT::SQL::error;
while ($orderlistxx = $sth->fetchrow_hashref)
{ push @orderlistxx, $orderlistxx; }
return { 8tableleftjoinloop => \@orderlistxx } }




i call it by



<%loop 8tableleftjoinloop%>
<%set counter += 0%>
<%if counter == 1%>its the first row<%endif%>
<%if counter == 8tableleftjoinloop.length%>
its the last row<%endif%>
do whatever you want here
<%endloop%> <div id="ocwrapper" class="clear">


and procude nothing .no error. but it is not the result i expected.
Quote Reply
Re: [courierb] how to translated to loop In reply to
As I said, you are calling it wrong ;) To access it as a loop - you need to do:

Code:
<%8tableleftjoinloop_gen%> <%-- this is what makes the loop --%>
<%loop 8tableleftjoinloop%>
<%if first%>its the first row<%endif%> <%if last%>its the last row<%endif%>
do whatever you want here
<%endloop%>
<div id="ocwrapper" class="clear">


And then with your new global: 8tableleftjoinloop_gen

Code:
sub {
my $ordernumber= '4646x';
# Displays links table join
my @orderlistxx;
my $search_db = $DB->table('orderlistxx','orderlistxx1');
my $sth = $search_db->select ( { orderidtrackm => $ordernumber}) || die $GT::SQL::error;
while ($orderlistxx = $sth->fetchrow_hashref) {
push @orderlistxx, $orderlistxx;
}
return { 8leftjoinloop => \@orderlistxx }
}

You MUST call the global before trying to do a loop. The loop_name and global can't be the same, as that won't work ;)

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] how to translated to loop In reply to
it is still get error

<%8tableleftjoinloop_gen%> where this come from . it is a alien. it is never been declared.

of course i have put your full code for a test. it is still produce a error.
Quote Reply
Re: [courierb] how to translated to loop In reply to
Please just send over GLinks admin details, and I'll do it for you. Taking too long to try and explain ;) (the code I gave above will work fine - but I think you are just not calling it right ;))

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] how to translated to loop In reply to
Ack - don't post details here!!!

I've edited them out ;0

Cheers

Last edited by:

Andy: Dec 29, 2008, 3:03 AM
Quote Reply
Re: [courierb] how to translated to loop In reply to
sorry for t the delay as i have to map the internal ip to be visible in the internet
Quote Reply
Re: [courierb] how to translated to loop In reply to
thx actually it is my pc . i do not scare of hacker . in case of it . i just do a ghost it again.
Quote Reply
Re: [courierb] how to translated to loop In reply to
courierb wrote:
sorry for t the delay as i have to map the internal ip to be visible in the internet

Hi,

No problem. Doesn't work for me though :) (btw, please use PM's to send details - cos its not safe posting login details etc on a puiblic forum ;))

I need to pop into town for a bit - but will take a look when I get back.

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: [courierb] how to translated to loop In reply to
i have call the global in the cool page
Quote Reply
Re: [courierb] how to translated to loop In reply to
Hi,

Should work fine now. You needed:

Code:
<%8tableleftjoinloop_gen%> <%-- this is what makes the loop --%>
<%loop tableleftjoinloop%>
<%if first%>its the first row<%endif%> <%if last%>its the last row<%endif%>
do whatever you want here
<%endloop%>

..and this global:

Code:
sub {
my $ordernumber= '4646x';
# Displays links table join
my @loop;
my $search_db = $DB->table('orderlistxx','orderlistxx1');
my $sth = $search_db->select ( { orderidtrackm => $ordernumber});
while (my $hit = $sth->fetchrow_hashref) {
push @loop, $hit;
}
return { tableleftjoinloop => \@loop }
}

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] how to translated to loop In reply to
you are great

Thank you andy.