Gossamer Forum
Quote Reply
New link Loop
I use this Global to show new link of category
sub {
my $cat = $_[0];
my ($output,$sth,$link);
my $all_ids = $DB->table('Category')->children($cat);
push @$all_ids, $cat;
my $search_db = $DB->table('Links','CatLinks','Category');
$search_db->select_options ('ORDER BY Add_Date DESC Limit 10');
$sth = $search_db->select (['Links.*'], GT::SQL::Condition->new(['CategoryID', 'IN', $all_ids], ['isValidated', '=', 'Yes', 'isNew', '=', 'Yes']) );
my $seen;
my $output;
while ($link = $sth->fetchrow_hashref)
{
if ($seen->{$link->{$id}}) { next }
my $category_url = $CFG->{build_root_url}."/".$link->{'Full_Name'}."/";
my $detailed_url = "$CFG->{build_detail_url}/$link->{'ID'}$CFG->{build_extension}";
$output .= Links::SiteHTML::display('sortlink', $link);
$seen->{$link->{$id}} = 1;
}
return $output;
}

Can I make the output send in a Loop - something like
<%loop new_link%>
-----------------
<%endloop%>
Quote Reply
Re: [nir] New link Loop In reply to
Hi,

Something like this should work:
Code:
sub {
my $cat = $_[0];
my ($output,$sth,$link);
my $all_ids = $DB->table('Category')->children($cat);
push @$all_ids, $cat;
my $search_db = $DB->table('Links','CatLinks','Category');
$search_db->select_options ('ORDER BY Add_Date DESC Limit 10');
$sth = $search_db->select ( ['Links.*'], GT::SQL::Condition->new(['CategoryID', 'IN', $all_ids], ['isValidated', '=', 'Yes', 'isNew', '=', 'Yes']) );
my $seen;
my $output;
my @loop;
while ($link = $sth->fetchrow_hashref) {
if ($seen->{$link->{ID}}) { next }
$link->{category_url} = $CFG->{build_root_url}."/".$link->{'Full_Name'}."/";
$link->{detailed_url} = "$CFG->{build_detail_url}/$link->{'ID'}$CFG->{build_extension}";
#$output .= Links::SiteHTML::display('sortlink', $link);
$seen->{$link->{ID}} = 1;
push @loop, $link;
}

return { new_loop => \@loop, rows => $sth->rows };
}

Call with:

Code:
<%global_name%>
<%loop new_loop%>
<%inlcude sortlink.html%>
<%endloop%>

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!

Last edited by:

Andy: Dec 13, 2007, 4:03 AM
Quote Reply
Re: [Andy] New link Loop In reply to
Putting something in @loop would help Laugh
Quote Reply
Re: [Wychwood] New link Loop In reply to
hahah well spotted :D (serves me right for trying to code before my morning coffee Tongue

I've updated the above code =)

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] New link Loop In reply to
Thanks Andy, is there an option that the global return the number of links it return. So I can write there are X new links.
Quote Reply
Re: [nir] New link Loop In reply to
Hi,

Give the modified version above a go. Then use <%rows%> to show the total :)

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] New link Loop In reply to
I use the "seem" for other column (company), so I can get a list of company. So if in 4 links I have 3 deferent companies with the global I will get a list of 3 companies.

If I insert in one like 2 companies (in the column company like – LG,Sony ) and in the other links this company are also submit, is there a why to get the global will know to remove duplicate?

What I main is if I have this 4 link can I get list of just - LG,Sony,Toshiba
Link 1 company- LG,Sony
Link 2 company-,Sony
Link 3 company- LG,
Link 4 company- Toshiba ,Sony
Quote Reply
Re: [nir] New link Loop In reply to
Hi,

The easiest way to do it - is install my ULTRAGlobals plugin (free) -http://www.ultranerds.com/...s/ULTRAGlobals_L217/

Then - in the

Code:
<%loop new_loop%>
...
<%endloop%>

Put the following where you want the category names to show:

Code:
<%Plugins::ULTRAGlobals::Get_Links_Categories($ID)%>
<%loop cat_loop_for_link%>
<a href="<%URL%>"><%Full_Name%></a>,
<%endloop%>

That should do the job Smile

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] New link Loop In reply to
Hi Andy, What I want is not the category names to show,
I want that in the category I will get list of company, I have column Name Company and the example display how I insert data to this column; I need to get a list of all companies without duplicate, so I use the global with the seem.

What I main is if I have this 4 links can I get list of just - LG,Sony,Toshiba
Link 1 company- LG,Sony
Link 2 company-,Sony
Link 3 company- LG,
Link 4 company- Toshiba ,Sony
Link 5 ...
Link 6 ...
Quote Reply
Re: [nir] New link Loop In reply to
Sorry, still don't really understand what you are asking Frown

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] New link Loop In reply to
What I mean is that I want to create a list of company names out of all the names that appear in the links.
So if I have these links:
Link 1 company- LG,Sony
Link 2 company-,Sony
Link 3 company- LG
Link 4 company- Toshiba ,Sony

The list will show:
LG
Sony
Toshiba

But right now when one link has two company names it reads both names and the comma between them like a new name so I get this list, with a lot of repetitions
LG,Sony
Sony
LG
Toshiba ,Sony

What I want is that it will know that the comma (or enter) separates two different names that should appear separately on the company name list, and to cancel the repetitions.
Quote Reply
Re: [nir] New link Loop In reply to
Is the "Company Name" a field, or a category name?

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] New link Loop In reply to
The "Company" is a field in the links.
Quote Reply
Re: [nir] New link Loop In reply to
Hi,

I think I understand what you mean now. Please try this.

Code:
sub {
my $cat = $_[0];
my ($output,$sth,$link);
my $all_ids = $DB->table('Category')->children($cat);
push @$all_ids, $cat;
my $search_db = $DB->table('Links','CatLinks','Category');
$search_db->select_options ('ORDER BY Add_Date DESC Limit 10');
$sth = $search_db->select ( ['Links.*'], GT::SQL::Condition->new(['CategoryID', 'IN', $all_ids], ['isValidated', '=', 'Yes', 'isNew', '=', 'Yes']) );
my $seen;
my $output;
my @loop;
my (@comp,$comp);
while ($link = $sth->fetchrow_hashref) {
if ($seen->{$link->{ID}}) { next }
my @company = split /,/ , $link->{Company};
foreach (@company) {
if (!$comp->{$_}) {
$comp->{$_} = 1;
push @comp, { Name => $_ };
}
}

$link->{category_url} = $CFG->{build_root_url}."/".$link->{'Full_Name'}."/";
$link->{detailed_url} = "$CFG->{build_detail_url}/$link->{'ID'}$CFG->{build_extension}";
#$output .= Links::SiteHTML::display('sortlink', $link);
$seen->{$link->{ID}} = 1;
push @loop, $link;
}

return { new_loop => \@loop, rows => $sth->rows, company_loop => \@comp };
}

You can then still use this:

Code:
<%global_name%>
<%loop new_loop%>
<%inlcude sortlink.html%>
<%endloop%>

..but you also have access to:

Code:
<%loop company_loop%>
<%Name%> <br />
<%endloop%>

Hope that helps.

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] New link Loop In reply to
It returns the companies list but it didn't cancel the repetitions
Quote Reply
Re: [nir] New link Loop In reply to
Do you have an example where I can see it?

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] New link Loop In reply to
Hi Andy
My mistakePirate, it workCool
Quote Reply
Re: [nir] New link Loop In reply to
Hi,

Great Cool

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!