Gossamer Forum
Quote Reply
Sorting
Alex,

One of the major points of 'mod' or 'change' is the sort order/sorting routines. Have you thought about allowing more flexibility in altering those settings to allow picking the sort order for different pages without having to modify the code directly?

Quote Reply
Re: Sorting In reply to
Is this different then:

# The default sort order for links.
$LINKS{build_sort_order} = "isNew,isPopular,Title";

This actually gets put straight into the SQL query, so you can throw in ASC or DESC in as well to change the order.

Cheers,

Alex
Quote Reply
Re: Sorting In reply to
Yes, a little.

For instance, it's nice to have the category pages in alphabetical order, or random order, while the "what's new" is in reverse date order, since people will browse down til they see something familiar.

There are many places where 'sort' takes place. These places should be turned into a variable/switch so that in the config file they can be set.

If you look through the Links 2.0 forum, you'll see all the different ways people want to sort. Several of them are pretty common -- and logical -- and should be incorporated.

Perhaps having several copies of
$build_sort_order
$build_sort_order_default
$build_sort_order_new
$build_sort_order_category
$build_sort_order_search

The subroutine passes it's 'local' setting of $build_sort_order variable, or default if it's set to null, to the sort routines if it exists in leu of the default.

Quote Reply
Re: Sorting In reply to
hi.. i know i'm not a links sql user.. but i started learning mysql (while learning php) today so.. i'll try to help.. [if this answer is off.. then ignore it Smile]

hehe.. ok.. i've been playing around with my copy of links 2 and mySQL and i got my categories into a sql databse.. which was really interesting and frustrating Smile

my query looks something like this (at this point)..

Code:
$que = "SELECT name FROM categories WHERE name LIKE '$string%' ORDER BY name $order";

it selects from the name field of the categories for categories that start with the scalar $string (which is defined in my query string.. and then it orders by name and then that $order thing at the end is for ascending and descending.. where i put this at the top:

Code:
if ($in{'order'} eq "d") { $order = "DESC"; }
else { $order = "ASC"; }

since i am not using links sql.. rather my own modded version of links2.. i can't give you a relavant answer..

wondering if that is sorta.. what you're looking for.. (this is sorta how i sort links.. for my category sort and search sort mods)..

jerry
Quote Reply
Re: Sorting In reply to
i think that is what i was talking about..

$a<=>$b just sorts everything in ASC order.. as $b<=>$a does it in DESC order..

jerry
Quote Reply
Re: Sorting In reply to
Jerry...

My 'wish-list' is more aimed at the a<=>b sorts, not the SELECT FROM type stuff.

For instance, you have to go in and change a to b and vice versa to change the order of the display on the What's New page -- that should be an 'option' so the users don't have to muck with DBSQL.pm itself -- the 'modules' should be as "no user serviceable parts inside" as possible, with all communications via passed values or functions.

On the What's New page... One might want the index page to list in reverse chronological order, and the daily pages to list randomly, aphabetically or alpha by category ---

Also, on the What's Cool, the ability to rank that page by various display options would be valuable too -- random, alpha, category, etc.

And displaying the entries as:

Category_1
link
Category_2
link

Rather than

Category_1
link
link
link
Category_2
link
link

Is better as well -- since a "what's cool" page should be ordered by hits, votes, activity, ratings, random or alpha, not artificially broken up by category. That makes it difficult to really see 'what's cool' since the 'coolest' link may be right next to the least coolest, with more popular links forced down the page due to category.

Anyway... that's what I mean.

SQL is great for other stuff... it really eliminates a lot of the jumping through hoops you have to do to make a flat-file system work.


Quote Reply
Re: Sorting In reply to
just a little thing i was wondering about SQL..

did you by any chance have to use:

something like this:

$nbr =~ s,0E0,0,;

to get rid of those annoying 0E0 if there were no links or something..

jerry
Quote Reply
Re: Sorting In reply to
Sorts -- agreed -- point being it should be a configurable option, not a source-code-edit.


I'm not sure what you mean by:

$nbr =~ s,0E0,0,;

I've used both Alex's routines, and basic DBI access, and haven't had a problem. Where are you getting that?

If a search turns up nothing, you should just ignore it along the lines of:

if $hits then {do whatever}
or
if not $hits {skip to the loo}

I haven't actually tried to parse a result that failed this test, if that's what you mean.

I've held off doing too much to Links, pending the next release -- since it's promising to be a real upgrade, and have been porting the postcards program I use under links to SQL, and adding a few user features to that. I haven't hit problems there, but all I'm doing is bsic "INSERT" and "SELECT" on the table, nothing much fancier.

Quote Reply
Re: Sorting In reply to
no.. it seems to me that 0 is equal to 0E0..

i dunno why.. just i had to parse it all the time.. when i use

Code:
$nbr = $sth->execute;

ndr equaling the number of results it returns..

jerry
Quote Reply
Re: Sorting In reply to
According to my reference, for a non-SELECT query execute() returns the number of rows affected, or -1 if the number of rows is unknown. For a SELECT query, some true value is returned upon success.

From the MySQL docs:

Quote:
execute
The execute method executes a prepared statement. For non-SELECT statements, execute returns the number of rows affected. If no rows are affected,
execute returns "0E0", which Perl treats as zero but regards as true. For SELECT statements, execute only starts the SQL query in the database; you need
to use one of the fetch_* methods described below to retrieve the data. Example:

$rv = $sth->execute
or die "can't execute the query: $sth->errstr;
Quote Reply
Re: Sorting In reply to
hehe.. i was taking shortcuts.. then realized i could have just put this one line after execute..

$nbr = $sth->rows;

gives me the right number..

jerry
Quote Reply
Re: Sorting In reply to
Hi Pugdog,

It shouldn't be too hard to do, I'll try and add it in (just a matter of looking where build_sort_order is used and changing it).

Cheers,

Alex
Quote Reply
Re: Sorting In reply to
Thanks Alex Smile

If you did the same for Links 3.0 you'd cut half the forum traffic Wink <G>