Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

Sorting Hits and set a counter?!

Quote Reply
Sorting Hits and set a counter?!
Hi there, has someone a clue about:
1. When building, after sorting give every link the position it has and write it to a field?

Example: I have three links, sorted for abc; then i want to show:
1. lala
2. lulu
3. lili

But i wont have only the position-number show (it could done simple by something like:
a=0
while ...
print a to tag
print link via link.html
a=a+1
)

I want to store this data in a field named counter before writing it.

Robert




Quote Reply
Re: Sorting Hits and set a counter?! In reply to
I posted a mod to the forum a few months ago for the "Build Cool" page that put a position number on each link found.

I think you could modify that to do what you wanted, just wrap your search routine in the same loop code. You could then use an "Update ..." command to put that number into that field in the Links record.

You can see it work at
http://postcards.com/...ostcards/pages/Cool/


http://www.postcards.com
FAQ: http://www.postcards.com/FAQ/LinkSQL/

Quote Reply
Re: Sorting Hits and set a counter?! In reply to
Thank you pugdog; i will search in a minute for that; when doing this my links topsites are ready as it seems.
Robert

Quote Reply
Re: Sorting Hits and set a counter?! In reply to
im searching ... and searching ... seems there is an important thing lost inside the forum: searching for the beginning of thread only by user; and searching for user and term.
Now i will try to see all the 5 Mio. entrees from you :-(
Robert

Quote Reply
Re: Sorting Hits and set a counter?! In reply to
Have done everything so far; but one big problem stays:

I have the $links_count in sub build_category_pages
and i have the rec->{'ID'} in sub site_html_link

but i need both at one place; so please help me:
how can i get the ID in build.cgi or the $links_count in sub site_html_link.

Both must be there, its logical, but i cant get them ...

Robert

Quote Reply
Re: Sorting Hits and set a counter?! In reply to
I'm not sure what code you are working on, but once you alter the "rec->" hash by adding in the new value, you pass the new value to the &build_link routine.

You can add the count by doing something like $rec->{'Position'} = &links_count

Now, when %$rec is passed, that is available as a tag in any of the templates that is called from that point in the routine on as <%Position%>

So, you count the link as you send each link to the link.html template, you add the $rec->{'Position'} = &links_count to the passed hash.

Is this what you are looking for?



http://www.postcards.com
FAQ: http://www.postcards.com/FAQ/LinkSQL/

Quote Reply
Re: Sorting Hits and set a counter?! In reply to
Thank you again; with a little trying i did it now.
Robert
Quote Reply
Re: Sorting Hits and set a counter?! In reply to
Please save my soul and tell me how i could get a field as a variable insite a sub (in HTML_Template.pm) called from build.cgi. I dont mean the <%tag%>, and i wont call a sub.
All i need is the value of a field from a table inside the sub. If the sub could get it to the template, it must be there, but i cant get it to a my $newvar = value_of_field.
Robert

Quote Reply
Re: Sorting Hits and set a counter?! In reply to
The value is in the $rec (usually) hash passed from one routine to another.

You need to look at the subroutine call, and see what values are passed, and then at the subroutine, and see what values the passed parameters are put into.

You need to just follow the parameters.

Remember, if the value is passed as $variable name, then it's a POINTER, if it's passed as a % or %$variable it's passed as the hash itself. If it's passed as a hash, the first values are pulled off and put into their own variables, with the rest of them put into a catch-all hash.

This is very complicated....

But, if you push the value into the "$rec" variable, you can pull it out in any sub routine by calling whatever variable the "$rec" variable is put into.

Does this make sense?

The <%TAG%> is not magic. It's actually just a clever use of the HASH capability of PERL. Any value that is eventually passed to &load_template can be used as a <%TAG%> since all parameters are put into a HASH and then referenced by the first string between <% %>

It makes some very easy programming. The _trick_ is to just put the stuff into the right HASH and pass it.

http://www.postcards.com
FAQ: http://www.postcards.com/FAQ/LinkSQL/

Quote Reply
Re: Sorting Hits and set a counter?! In reply to
Cause i think you would know what you say, it shurely makes sense, but i understand no word :-)

Please, please, please give my only the syntax for
my var = XXXX;

I will add now the real part of my script:

sub site_html_print_cat (in HTML_Templates)
...
my ($output, $category_name, $category_url, $i, $cat, $cat_r, @subnames);
my $breakpoint = int (($#names+1) / $LINKS{build_category_columns}) + ( (($#names+1) % $LINKS{build_category_columns}) ? 1 : 0);
##--##
my $cols = 0;
if ($cols){
$breakpoint = int (($#names+1) / $cols) + ( (($#names+1) % $cols) ? 1 : 0);
}

OK, here we go, if the variable $cols is existent, give for that category another number of cols.

But how could i get this $cols; it must come from a field named Cals in the Cat-Table:

sub build_category_pages in build.cgi
...
# Get the category info.
%OUT = (); # Start with a clean hash.
$OUT{category_id} = $category_r->{'ID'};
$OUT{category_name} = $category_r->{'Name'};
$OUT{header} = $category_r->{'Header'};
$OUT{footer} = $category_r->{'Footer'};
$OUT{meta_name} = $category_r->{'Meta_Description'};
$OUT{meta_keywords} = $category_r->{'Meta_Keywords'};
$OUT{description} = $category_r->{'Description'};
$OUT{cols} = $category_r->{'Cols'};
...

# Clean up the name.
...

# Fetch the subcategory list.
$subcategory_r ? ($OUT{category} = &site_html_print_cat ($subcategory_r)) : ($OUT{category} = '');

Ok, here my vars go to the sub above; now it should be:

my $cols = $subcat->(Cols);

But unfortunately its wrong!
Robert















Quote Reply
Re: Sorting Hits and set a counter?! In reply to
Hi Robert,

I assume that you have a field called 'Cols' in your category table.

In the sub build_category_pages you get the value in
$category_r->{'Cols'};(retrieved fom the database)

You add it to the hash $Out
$OUT{cols} = $category_r->{'Cols'};

Now you call &site_html_category (\%OUT);
(you don't pass the hash; only a reference to it)

Here we are in site_html_category
It start with the code:
my ($tags, $dynamic) = @_;

In your code you define
my $cols = 0;
if ($cols){ ...
! The if clause will always return FALSE because $cols=0; !

if you want to get the value of $cols, you must get it out of $tags.

my $cols = $tags->{'cols'};
if ($cols){ ...

Now you can evaluate $cols and do anything you want with it.

regards, alexander


Quote Reply
Re: Sorting Hits and set a counter?! In reply to
Hmm, i have made this error:

I jump first to the !!! site_html_print_cat !!!

So i try:
# Get the category info.
...
my $test = $category_r->{'Cols'};

and show it when building to see if its right done with:

#print out diag info
...
print "\tExtrafield Cols: <b>$test</b>\n";

OK, so far.

now i muss pass $test ,too:

# Fetch the subcategory list.
$subcategory_r ? ($OUT{category} = &site_html_print_cat ($subcategory_r, $test)) : ($OUT{category} = '');

At this point i pass the value for my field Cols, too.

Then in the sub i should have ($subcategory_r, $test)
inside the array: $subcat

But how would perl know that in $subcat now is an array and a skalar?

Maybe it has the values $subcat($subcategory_r, $test)
while $subcategory_r is self an array, and $test the skalar;
then i should do:
my $cols = $subcat->{test};

But this dont work.

Robert
Quote Reply
Re: Sorting Hits and set a counter?! In reply to
Hallo Robert,
bitte schreib mir eine email auf deutsch und ich helf dir weiter. Silberling@t-online.de

Grüße, ALex

Quote Reply
Re: Sorting Hits and set a counter?! In reply to
Thank you Alex, i just did it.
Mit referenziert referenzierten Referenzen referenziert :-)
Robert