Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Allow sorting links dynamically by price via category.html and search.cgi

Quote Reply
Allow sorting links dynamically by price via category.html and search.cgi
I have a price filed in the links table. What I want is to provide way so the users can sort category page links and/or search results DYNAMICALLY via search.cgi by Ascending/Des price or High/Low price like so -

<"/cgi-bin/search.cgi?Price=Asc">Sort links Ascending</A>
OR
<"/cgi-bin/search.cgi?Price=High">Sort links by Highest Price</A>

So, basically I want to put links in category.html and/or search_results.html which connect to search.cgi and when clicked upon will rearrange links with High/Low price.

One thing to note though is that some links have commas and decimals in the price field and some don't but I want the search to ignore commas and decimals and just straightaway sort links based on price.

Thanks!
Quote Reply
Re: [socrates] Allow sorting links dynamically by price via category.html and search.cgi In reply to
Hi,

I thought we already discussed this?

http://www.gossamer-threads.com/...%3F_P316813/#p316813

Anyway, you should be able to do it with something like:

search.cgi?query=*;sb=price;so=asc
search.cgi?query=*;sb=price;so=desc

sb = sort by (the column name)
so = sort order (asc or desc)

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] Allow sorting links dynamically by price via category.html and search.cgi In reply to
Thanks Andy,

search.cgi?query=*;sb=price;so=asc
search.cgi?query=*;sb=price;so=desc

Yes, that is what I wanted to know with regards to sorting but there are a couple of issues -

First, in the earlier thread it works fine the way I want but I have to enter either catname or query=something. It doesn't work if the query=blank or query=* itself and I think that is because the search.pm requires some input. Withe the earlier codes, it would be nice if the query is blank then it will return all listings which I can sort, but for the time being setting that aside the other issue is, below.

The sorting itself does not seem work well because of commas in the price values - hence, I thought we might need a global or something so it sorts the values ignoring the commas - in the future I plan to add a javascript in the form so users submit commas in price values, it will reformat before submitting the price value to the database.

For now, is it possible to run a sql query to remove commas from price values - and if so how?

Thanks!
Quote Reply
Re: [socrates] Allow sorting links dynamically by price via category.html and search.cgi In reply to
Hi,

You could try changing:

return search() if ((defined $args->{query} and $args->{query} =~ /\S/) || $args->{catid} =~ /^\d+$/);

to

Code:
return search()
if (
(defined $args->{query} and $args->{query} =~ /\S/)
||
$args->{query} eq "*"
||
$args->{catid} =~ /^\d+$/
);

to see if that helps. Then pass in query=* to make it do a search. If that doesn't work, I'll need to look deeper.

Quote:
The sorting itself does not seem work well because of commas in the price values - hence, I thought we might need a global or something so it sorts the values ignoring the commas - in the future I plan to add a javascript in the form so users submit commas in price values, it will reformat before submitting the price value to the database.

Or better yet, add another field (basic FLOAT field), and do something like:

Code:
UPDATE glinks_Links SET New_Field = REPLACE(Current_Price_Field,",","")

Or better yet, would be to STORE the data *without* any comma's in, and then use my Commify() function in ULTRAGlobals to format it only when you need to show it with commas.

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: [socrates] Allow sorting links dynamically by price via category.html and search.cgi In reply to
Hey socrates,

I think Andy gave the desired repy, just wanted to add my bit of comment.
Are you using a char/varchar field for your prices?
I would expect FLOAT, REAL, DOUBLE or anything like that to sort correctly.
If so I suggest switching to one of the above field types and if you want to have , instead of . in your output you should modify it with a global.

And maybe I misunderstood something but I would not recommend sorting by price combined with build_search_gb enabled.

Regards

Niko
Quote Reply
Re: [el noe] Allow sorting links dynamically by price via category.html and search.cgi In reply to
Thanks to both Andy and El Noe but I haven't done anything since my last post and will try this later.