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

Display link away from others?

Quote Reply
Display link away from others?
Hi - I think this is fairly simple. Basically I am setting up a directory of fan pages and want to be able to display Official fan sites on the same page as the unofficial fan sites but in a different place.

i.e.

Official Site: http://www.whatever.com

Unofficial Sites:
http://www.whatever.com
http://www.whatever.com
http://www.whatever.com

I know I need to add a field to Links and use a IF statement but I am having big problems!

Geoff.


Quote Reply
Re: Display link away from others? In reply to
What you would have to do is the following:

1) Add the following field in your Links.def and Validate.def files:

Code:

isOfficial => ['16', 'CHAR', '0', '1', '1', 'N', 'Y|N'],


Change 16 to the last field number in the %db_def hash.

Then add the following codes in the %db_select_fields hash:

Code:

isOfficial => 'Yes,No'


Make sure that you put a comma at the end of the line before the last field in this hash.

2) Then in your Links and Validate tables, add the field as follows:

Code:

isOfficial ENUM ('Y', 'N') NOT NULL DEFAULT 'N',


3) Then in your admin.cgi file in the Links section, modify the links that you want to be official with Yes

4) Then read information about using the Priority link modification discussed in this forum and pugdog's LINKS SQL FAQ site (which is linked in the Resource Center).

Regards,

Eliot

Quote Reply
Re: Display link away from others? In reply to
"2) Then in your Links and Validate tables, add the field as follows"

What do you mean the links and validate tables? Do I do this using the admin.cgi online control panel or something else?

I am a bit of a novice. Do I include <%if official%> in the template? Please explain :-)

Geoff

Quote Reply
Re: Display link away from others? In reply to
You do this via the Table Maintenance option. Or you could simply add the field in your SQL.mysql file and then re-create your tables.

In Reply To:
I am a bit of a novice. Do I include <%if official%> in the template? Please explain :-)
NO...You use the isOfficial field in the Priority Sort Mod, which has been discussed before in this forum and I believe linked in the Resource Center. It will sort the OFFICIAL sites first and then the UNOFFICIAL sites after like you originally requested in your first posting!

Regards,

Eliot Lee

Quote Reply
Re: Display link away from others? In reply to
Eliot,

It's not just that I want Official sites to be listed first. I want to be able to display them on the same page but away from the main body of links.

Look forward to your reply.

JeffB

Quote Reply
Re: Display link away from others? In reply to
Well, it is my understanding that the Priority Link Mod will do this for you. Have you even tried searching the forum for information about the Priority Link Mod????

Regards,

Eliot Lee

Quote Reply
Re: Display link away from others? In reply to
Yes I did and couldn't really find that much helpful stuff. I have one last question. When you go to add the new field using the control panel you don't get the option to set 'ENUM' and things like that. It asks you for Column Type, Form Length, Max Length, Not Null, Default Value, Validation, Index Weight

How do I add the field like you specify in the thread above? I hope this will be useful for other novices out there :-)

JeffB

Quote Reply
Re: Display link away from others? In reply to
This was addressed a week or two ago for someone wanting to put approved, or reviewed sites (or something like that) at the top of the listing.

I know, because we spent a bit of time trying to get the links to all display on the top of the first page, not the top of each page.

You are doing the exact same thing.

The code will be the same, the process the same, and the results the same.

A little reading of the forum will eliminate many of the questions. If you are planning to modify any program, you need to gain an understanding of it. Personally, I always start with reading the forum for at least a week or two, and working backwards through as many messages as I can, printing or saving those that seem to answer questions I'm sure to bump into.

I'm really glad Elliot is here now, to handle some of the load, since I was reaching my frustration point at the repeat questions, often with in days or less of each other.

The last time I hit that point, the FAQ site was born.

I've admitted I've let the site sleep, because with things changing so radically in the next release, the 1.11 version _should_ quickly become obsolete, and/or anyone still using it will not need the general help offered there.

Alex promises documentation for the next release, which will be at least a good starting place.

This is a user support/help area. No one here except Alex is paid -- directly or indirectly -- for support. If you have a problem, or a need, the first thing to do is READ THE FORUM. Try searching in as many different ways as you can, then _at_ _least_ read 30 days of messages, so you don't increase the people who help out frustration level. I answer questions to help out, and to help think through problems -- the first time. By the 3rd time, it starts to wear thin.

The #1 reason for people dropping off newsgroups or messages boards is frustration with the same questions over and over, and the flame wars that inevitably result. Last time, as I said, I set up the FAQ, and got my frustrations out that way.

It may be _your_ first question, but it's been asked, answered, filed, and beat to death before.

This time, fortunately for me, before I flamed out, I was forced to rebuild my home network and add a computer, which under Windows takes a good 7-10 days. I've moved my network from software back into hardware, added a fast machine for internet work, and removed the network support from the graphics machine, so I now have 2 stable machines on my desk, instead of 1 flakey one, as well as the other support machines. First new hardware in almost a year (not bad -- speaks to the quality of the new electronics, or the lack-of-quality of the old ones).

But, this priority/official/whatever mod was _just_ discussed, worked out, and posted not more than 2 weeks ago, maybe less.

There has been an increase in multiple, duplicate, and redundant questions and posts to the forum in recent weeks, and the tide needs to slow. At one point, 3 different people asked the same question, in the same forum, within 24 hours of each other, with almost the same subject.

I'm hoping that once the new version comes out I'll be up to adding to the FAQ again, and people will be able to say -- RTFM and/or RTFFAQ.

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

Quote Reply
Re: Display link away from others? In reply to
Pugdog.

I did read the other thread on this topic and feel annoyed at being told off for not understanding the very long thread.

As you can see there are many conflicting and similar solutions posted on the old thread:
http://gossamer-threads.com/p/86226

I was hoping to clarify which the best solution was and then I thought I would make it into a mod for other new users in the future. I hope you will re-consider and if necessary copy and paste the best solution to this thread.

Thanks :-)

JeffB


Quote Reply
Re: Display link away from others? In reply to
I just looked at the thread.

The solution is in there, it works, and all you need to do is follow it.

It will put the "isFeatured" at the top of the main page, or where ever you want to place it, and not the other pages, while still allowing the links to appear on the pages.

If you have a specific question about that mod, or why it's not working for you, please post that. But this has already been solved once. This is what I mean about multiple postings/requests/etc.

The solution is already in the forum.



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

Quote Reply
Re: Display link away from others? In reply to
OK - I will make this simple.

Do I follow JerrySu's Solution or Pugdog's? That's all I am trying to work out and I don't see why it is such a big deal to tell me which solution to use when 2 different ones are in the same thread.

I look forward to a more helpful reply.

JeffB

Quote Reply
Re: Display link away from others? In reply to
Actually...Dan Kaplan's Featured Site Mod, which has recently been linked again in this forum in the last few days is much better and will do what you want.

Regards,

Eliot Lee

Quote Reply
Re: Display link away from others? In reply to
Elliot, you trouble maker <G>


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

Quote Reply
Re: Display link away from others? In reply to
I just took a look at the mod at his site (run-down.com) and it does NOT do what I want. His mod takes a random link from a text file and makes it featured.

What I want to do is for the program to check whether there is a featured link within the specific category and <if> there is then it displays it on the category's page. Some categories will have featured sites and some will not.

Can nobody help me? Surely it can't be that difficult for the Pros - but they seem reluctant to actually post a solution - instead they just say "posted already" without a link or specific example.

Regards.

Quote Reply
Re: Display link away from others? In reply to
If you know anything about Perl...you can delete the random codes (srand) and then simply print all the "isOfficial" sites. Either way...you can use Widgetz's Mod or Dan Kaplan's Mod!

Regards,

Eliot

Quote Reply
Re: Display link away from others? In reply to
Jeff,

The code _IS_ posted in the previous thread. I clearly gave the code and lines to change to make it work. I even gave the code to put in the template.

You need to first pull out all the "featured" links, put them into one variable, then build the pages normally. If you only want the featured links to occur on the first page, you need to reset it to '' before entering the 'span pages'loop.

The user who had the problem did the debugging, so we know it works, and I fixed the '}' problem, so as not to confuse people who didn't read the whole thread.

I honestly don't see what the problem is.

If you've already modified your file (that routine) then you can either go back to the original archive, and use the original file, or think through the modifications you've made and insert these as well.

If you'd like someone to do that for you, my rates start at $75. I'm sure there others who are cheaper.

Just for the record:

Code:
Just above the comment line:

# If we are spanning pages, we grab the first x number of links and build
add this:


##################### corrected 07/12/00 (see following message)
for my $i (0 .. $numlinks - 1) {
$tmp = $LINKDB->array_to_hash (${$links_r}[$i]);
if ($tmp->{Priority} > 0) {
$OUT{featured} .= &site_html_link ($tmp);
}
}
#####################

That above section of code goes through all the found links looking for
any that are priority, and assigns them to the "featured" tag.

Remove all the other edits you made between the ######## bars, except for
the:

#######featured###########
$OUT{featured} = "";
#######################

which you leave right above the begining of the remaing page builds:

# Then we go through the list of links and build on the remaining pages.

If you want the featured items to appear on EVERY build page, just don't add
the $OUT{featured} = ""; line.
NOTE: This assumes your field in the table is called "Priority". If you call
it "Featured" or "isFeatured" or anything else, you need to change the "if" test if ($tmp->{Priority} > 0) to reflect whatever the field name is.

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

Quote Reply
Re: Display link away from others? In reply to
Pugdog,

Thanks for that. I worked it out and learnt a little more about Perl. We would be happy to hire you in the future and please e-mail your payment details etc. to sales@celebhoonetwork.com

One final question on this thread!!

Q: How do you stop the <%featured%> (priority) link showing up twice on the page? We want it only to show up under the official area and not also under the UnOfficial area (!)

Please post solution here - not only for me but others too :-)

JeffB

Quote Reply
Re: Display link away from others? In reply to
That's not as simple as it appears, especially if you are counting links.

You need to remove the link from the ARRAY, not a hash (the array is used
to preserve order, hashes are unordered). Removing from an array is more complicated, since they are ordered. If you remove element 'n', there is an empty 'hole' where that 'value' used to be, but the n-th element still exists. Unlike a Hash where delete($hash{key}) removes the element, no problem.

So, you have to compact the array. In most languages this means copying the array or shifting each element after the tossed one down, then cutting the array size by 1. PERL of course, has a function to do that.

There are several ways to do this -- set the element to null, then copy the old array to the new one, generate a new array as you iterate the old one, etc. Each of these probably has merit, and may be less CPU intensive, and better performance, but requires more code to make it work.

Or, use the PERL function and worry about peformance later if it's a problem.

The simplest solution is to use "splice" and shift everything down. This is assuming that there are only going to be a few "featured" or "official" sites in each category.

As you iterate the original sorted array, you need to REMOVE the element you found that matches the 'featured' criteria. Then, because the array has changed size, you need to decrement $numlinks & $i by one, to start up again AT THE CURRENT POSITION (there are other ways of doing this -- such as using $#array, but that probably requires a computation each iteration, and if it doesn't, then it may fail).

This also makes 2 assumptions that I can't test (since I don't have this mod installed on my sites).

1) that PERL allows you to change the initialization variables from inside a loop.

2) that @$links_r properly dereferences the array.

Code:
#####################
for my $i (0 .. $numlinks - 1) {
$tmp = $LINKDB->array_to_hash (${$links_r}[$i]);
## $tmp is now a pointer to a hash of the Link values _NOT_ an array pointer!
## delete()ing tmp would do nothing to the original array elements.
if ($tmp->{Priority} > 0) {
$OUT{featured} .= &site_html_link ($tmp);
splice (@$links_r, $i, 1); ## need to dereference the array
$numlinks=$numlinks-1; ## need to reset the size of the array
$i=$i-1; ## need to re-check the new element $1
}
}
#####################
$numlinks, as a variable scoped to the subroutine, is altered in the loop, and should take on the new value/size of the array at the end of the loop.

This should properly preserve the link counting, and not go off the end of the array, but you might want to look at resetting the following variables:

Code:
$OUT{total} = $numlinks;
$total_links = $numlinks;
These values will include the "featured" links as well ("Official" in your case). You might want to keep track of the two different totals, and you can do that by creating new $OUT{value} variables to pass to the template.

If you try to use those values in the code from this point on, you will get an out-of-scope (or whatever) error as PERL tries to read array elements that don't exist and have not been assigned.

I don't know if this works, so let me know.

Someone else may have a more 'elegant' solution to this, since I freely admit I'm not a code guru with any of this.

In any case, adding those lines shouldn't do any damage, at worst they'll generate an error.

This has benefits of _NOT_ doing two SELECT statements, but you might get better performance if you did.

Code:
my $get_plinks = $LINKDB->prepare (" SELECT * FROM Links
WHERE CategoryID = ?
AND Priority = 'Official'
ORDER BY $LINKS{build_sort_order_category}
LIMIT 1000 ");

$get_links = $LINKDB->prepare (" SELECT * FROM Links
WHERE CategoryID = ?
AND Priority != 'Official'
ORDER BY $LINKS{build_sort_order_category}
LIMIT 1000 ");
You then use $get_plinks to generate a list, and use that in the "featured" subroutine, then use $get_links in the regular subroutine.

My problem with is is that the UNION of the two searches above, _SHOULD_ equal the original search query (without the Prority=xx). But it may _NOT_.

By scanning the original found list, and breaking it up, you eliminate some potential errors that could have you going around and around for hours or days before you realize it's differences in the SELECT statements that cause the problem.

Then, again, by using two searches, if you have 1000 "unofficial" sites, and 32 "offical" sites, you'll find all 1032 sites, but with the original single query, you'd only find the first 1000 sites, and depending on the sort parameter, it could be the 32 'official' sites + 968 'unofficial' sites, or 1000 unofficial sites, and no featured sites.

Anyway, let me know if this works.

-----------
The question of "how much" comes up regularly in the forum, and in email. In case anyone is interested in the "costs" of programming, this tiny (3-line) mod to an existing mod would probably be a $75-$100 billable item if you requested it from a programmer. The problem was analyzed, 4-5 different solutions were considered, one was picked and implemented, along with other 'possibilities.' References were checked, code was commented, logic documented, and put down. Of course that would also include the 'debugging' part, which I'm leaving to you. It's not just 3-lines of code. I'll do this from time to time now, just as a reality check. FWIW: this was a bit more complicated/tricky thing to work out than it appeared on the surface due to the arrays, not hashes, where the rest of Links is all hashes.
-----------


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

Quote Reply
Re: Display link away from others? In reply to
I replaced the old mod:


for my $i (0 .. $numlinks - 1) {
$tmp = $LINKDB->array_to_hash (${$links_r}[$i]);
if ($tmp->{Priority} > 0) {
$OUT{featured} .= &site_html_link ($tmp);
}
}


with your code above, i.e.


for my $i (0 .. $numlinks - 1) {
$tmp = $LINKDB->array_to_hash (${$links_r}[$i]);
## $tmp is now a pointer to a hash of the Link values _NOT_ an array pointer!
## delete()ing tmp would do nothing to the original array elements.
if ($tmp->{Priority} > 0) {
$OUT{featured} .= &site_html_link ($tmp);
splice (@$links_r, $i, 1); ## need to dereference the array
$numlinks=$numlinks-1; ## need to reset the size of the array
$i=$i-1; ## need to re-check the new element $1
}
}


But I get this error when I build:

DBSQL (9687): Fatal Error: Invalid argument type '' passed to array_to_hash at nph-build.cgi line 461

Did I need to add any other code around the new code or what have I done wrong?

JeffB



Quote Reply
Re: Display link away from others? In reply to
I'd need to see the whole subroutine. What it's essentially saying is the argument is not being passed at all -- It's '' (null). Somewhere, it's being lost. The changes we made are AFTER that point, so either the splice command is not working right, or perl doesn't like the loop counter reassignments.

I may have to try to run this to see what is happening, but I can't do it right now.



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