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

AlternativeCategory sort problem who fixed it ?

Quote Reply
AlternativeCategory sort problem who fixed it ?
Hello all,

I have alternative links and there seems to be a big sort problem in it. I have to get this working, because i can't wait for the next version. I am stuck on it like 6 days now.....

What's the problem?
If you select 1 or more alternative category in a links then sort won't work propper.
I was first thinking it didn't work because i tried to sort on add_date but also on other field like title the sort is not working good in the category pages, it sort 'random' instead of title, add_date ASC/DESC or whatever you select.

- Who is using alternative links in version 1.11 ? Do you also have the same problem ?

Does ANYONE know how to FIX this BUG ?

I hope someone can help me on this, because i had it with this problem ARGH#$%#@ ......

Regards startpoint.

Quote Reply
Re: AlternativeCategory sort problem who fixed it ? In reply to
Hello all,

Well i restored some orginal code and figure out that the problem is this:

It sort's the alternatecategory links then display it, after that comes the links sorted. But i want them all merges and then sort on example title.


Example category page listing and sort on title:

This is it now:

Code:
AlternativeCategory/Link Title
A Hello i wanna sort this all together sqllinks FAQ
A Only 2 links are marked as AlternativeCategory Links
L I am a normal link
L Zero bytes
But i want it all combined like this:

Code:
AlternativeCategory/Link Title
A Hello i wanna sort this all together sqllinks FAQ
L I am a normal link
A Only 2 links are marked as AlternativeCategory Links
L Zero bytes
Hope anyone has a solution ?

Regards startpoint.



Quote Reply
Re: AlternativeCategory sort problem who fixed it ? In reply to
As I said, two potential fixes, both are cpu-resource hogs, and I don't know anyone who has implemented them.

I short, there is no "fix" for this.

It's an artifact of the original code.

Hopefully it will be altered (couldn't resist) in the next code.

Basically, you'd want to merge the links and alt-links tables BEFORE doing anything to them.

The problem is that to put alt-links into the links table, you'd be wasting incredible storage resources, and violating all sorts of rules of database normalizing, to keep the two links in different tables requires either doing it the way it's done now, then inserting the alt-links into the hash of retrieved values _BEFORE_ attempting to sort them, (but this means you have to do a re-sort on the values that were taken out of the database sorted, and you can't use a "HASH" you have to use an arrary or linked list).

If you just stored pointers to each set of links, then you'd have to do one lookup/database-access PER LINK, so if you found 1000 links, you'd have 1000 database accesses, rather than 2.

So, you see the problems?

The most "logical" solution would be to create a temporary table, insert the first select statement of links into it, then insert each of the alt-links into it, then re-select all the links, and empty the table.

Again, EXPENSIVE, but if the #of alt-links is always small relative to the number of hard-links, then the expense is less than any of the other two methods, which incur expense at each step.

So, in short, there is no reason to post a dozen more messages about this. There is NO fix for it. If you'd like to write one, feel free. If someone has done it, I'm sure they will post it. But until I see the first beta release of the next links, I'm not going to attempt to fix it, since it would be a waste of time, if the base logic was fixed in the next release.

This is a known bug, it's annoyed plenty of people, but because we are working with hashes of hashes, and this would have to be done with ARRAYS, you'd have to write new routines, or do a lot of conversion back and forth.

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

Quote Reply
Re: AlternativeCategory sort problem who fixed it ? In reply to
Thanks pugdog you have make your point....

So i have to find another solution (and leave alternativecategory links) because i want to keep it quick.

Because i will only 13 category's i am thinking to do it a other way but can you tell me if this works?

In table Links i will add 13 extra (with name of a category) fields with value yes|no and displayed as a checkbox.

Where the category pages are build in nph-build.cgi and display in page.cgi some code i will have to change i quess to get this working. Hope you see what i mean ?

So basically i will not use the category-id in the links table. But i will use the category table to build static category pages where Category_name.category = field [Category_name].Links.
I allready got the new and cool page working because i adjusted the select routine to only links table.

But the hard part is the code in nph-build.cgi for the static category pages i quess, maybe you can give me some hints ?

Allready thanks.

Startpoint.
Quote Reply
Re: AlternativeCategory sort problem who fixed it ? In reply to
Ok,

I'm not following exactly what you are saying, but:

With only 13 categories, if that is what you are doing, then _yes_ add 13 fields to each of the database links (well, just the database table would do it).

Then, define those fields as db_checkbox in the .def file (or whatever those are) -- there are several threads on making that work -- and it will do all the work for you in the Admin.

Then, in your ADD and MODIFY you'd have to add the fields to the HTML templates.

To do this, rather than Yes/No, use 1/0. That is better, and will save some cpu cycles.

In the templates you can then use <%if%> tests to check/uncheck the boxes. (other means are non-portable, unsafe tricks).

(You'll have to see how that works with the db_checkboxes in the Admin though, and use the format that gives the path of least resistance)

Then, in the SELECT phase of the process, when you SELEcT the links for each category, change the SELECT statement to select on the category_field, rather than the category_id.

Now, you might find some benefit using the Category_ID _as_ the value of the Category_Field_x (you might have to use some temp variables if this doesn't work):

Code:
$Category_Field = 'Category_Field_' . $in->{Category_ID} ; ## current category
## mabye $OUT{ID} ??
and something like

$in->{$Category_Field} would contain the value of the Category_Field_x column
for each "link" record. It's a _created_ variable, and you'd need to assign it
to _each_ link as found, but it would make the logic of following the code less
bug prone. The $Category_Field variable woud not change til you updated the $OUT hash again.
since you could then do a select similar to:

SELECT * FROM Links
where $in->{$Category_Field} = 1

Following?

With only 13 categories, you could also do something like storing the alt-links in one table field, but I think the expense of the extra table columns for only 13, or 20, or some low number, makes up for the loss of performance trying to get tricky.

In the add, modify, Admin, etc areas, you'd only work with the "primary" category, since we'll ignore everything else, then check the boxes for _all_ the categories the link needs to be in, _including_ the primary category.

You could probably add a line of code to assign the primary category (Category_ID) to it's appropriate checkbox in the "validate" area, just to be certain, it would be one, maybe two lines of code.

Now, --- my disclaimer. I haven't tried this. It's ugly, and I'd never implement it. I just woke up from 2 hours of really lousy sleep in a way too hot room, 10 hours after getting only 3 hours of sleep the night before.... so if this works, I'll be more surprised than you ;)

The _logic_ is probably valid, the code I would not want to type in <G>

Ok.... that said, go for it.



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

Quote Reply
Re: AlternativeCategory sort problem who fixed it ? In reply to
Wow what a post, well i though i was funny but you break the long post reply record !!! Thanks for your thinking.

In Reply To:
With only 13 categories, if that is what you are doing, then _yes_ add 13 fields to each of the database links (well, just the database table
would do it).

Then, define those fields as db_checkbox in the .def file (or whatever those are) -- there are several threads on making that work -- and it
will do all the work for you in the Admin.

Then, in your ADD and MODIFY you'd have to add the fields to the HTML templates.

To do this, rather than Yes/No, use 1/0. That is better, and will save some cpu cycles.
I did that before i watch your reply, only i use yes/no Smile.


The part after the quote about i have read it 2 times now, but didn't get it all. So i will try to read it again later, when my head is cleared. It's now 2.36 am here!


But to make it clear to you.

- I now have 12 extra checkbox fields in table Links and it's working ok because i did some mod/bugfix i found about db_checkbox in the forum.

My problem is in nph-build.cgi to make the category pages.

Because i will not have a main category (i did even use categoryid) the code in nph-build.cgi have to be different.

In Reply To:
Then, in the SELECT phase of the process, when you SELEcT the links for each category, change the SELECT statement to select on the
category_field, rather than the category_id.
Yeah something like that, i quess i have to change this line in nph-build.cgi:

$get_links->execute ($category_r->{'ID'});

Right ?

Let say it starts building a category page in category 'Computer'.
- Then i have to select (somewhere) all the links where field name Links.Computer = yes

eh...

Links.computer = Links.[category.Name]

Hope you get what i mean, any ideas what code to mod ?

BTW: I will not use links.categoryid at all and i have entered 12 category's in the table Category with are also fields in the table Links.


Regards startpoint.


Quote Reply
Re: AlternativeCategory sort problem who fixed it ? In reply to
Aha i also found a line in page.cgi what have to changed i quess.

$get_links = $LINKDB->prepare (" SELECT * FROM Links WHERE CategoryID = ? ORDER BY $LINKS{build_sort_order_category} LIMIT 1000 ");

Don't know what to change yet, but it looks easier then in static mode. But i need it working in static and dynamic mode grrrrr :)...

eh... this part CategoryID = ?

has to be change to something like:

CategoryName = Links.$CategoryName and Links.$CategoryName = "Yes"

Does this work you think ? What about the static mode .....

Allready thanks...

Regards Startpoint