Gossamer Forum
Home : Products : Gossamer Links : Discussions :

How can I include a dropdown menu to search by category?

Quote Reply
How can I include a dropdown menu to search by category?
Hello folks! I purchased Links SQL 2.1.0 a few months back and have finally reached a point where I need to consult with the resident gurus here at the forums. What I'd like to do Is add a dropdown menu next to my search forms so users can narrow their search to the single or multiple top-level category of their choice. Or just leave it at default and query the entire directory. I think it's possible since I've seen a similar selection form on other sites using Links....Just can't figure out how. Also would there be some way to make that menu include new additions or changes to the category names?

Thanks so much for any help or suggestion for making this feature or something similar!!!!

Best REgards,

Ryan Jonze
Quote Reply
Re: [Jonze] How can I include a dropdown menu to search by category? In reply to
Hi,

You'd need a global to display the top level categories. In your template put:

Links Only in: <select name="catid"><option value="">All</option><%top_categories%></select>

and then in your globals add:

top_categories =>

Code:
sub {
my $cat_db = $DB->table('Category');
$cat_db->select_options ("ORDER BY Full_Name DESC");
my $sth = $cat_db->select ( { FatherID => 0 });
my $output = '';
while (my $cat = $sth->fetchrow_hashref) {
$output .= "<option value='$cat->{ID}'>$cat->{Name}</option>";
}
return $output;
}


That should do the trick.

Cheers,

Alex
--
Gossamer Threads Inc.

Last edited by:

Alex: Mar 28, 2002, 9:46 AM
Quote Reply
Re: [Alex] How can I include a dropdown menu to search by category? In reply to
Hi Alex Wink

Thanks so much for your help! I added your top_categories global then updated my templates but recieved this fatal error:

A fatal error has occured:

GT::Config (25014): Unable to compile 'top_categories ' in file 'blah/blah.../globals.txt': at blah/blah.../cgi-bin/search/admin/GT/Template.pm line 461.

Have any Idea what may be the problem?

Best REgards,

Ryan Jonze
Quote Reply
Re: [Jonze] How can I include a dropdown menu to search by category? In reply to
Can you try it again? I've updated the global.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] How can I include a dropdown menu to search by category? In reply to
That did fix the error Alex, but it only shows the "All" option in the selector form. Searches still work properly but I just can't select from top categories since their not available. So close!

Thanks for the time Alex

Best Regards,

Ryan Jonze
Post deleted by Jonze In reply to
Quote Reply
Re: [Jonze] How can I include a dropdown menu to search by category? In reply to
Alright!!! It's working great.Sly

I ended up deleting the updated top_categories global and resaved it which got it working properly...

Also had to get rid of the under score in the <select name="cat_id"> to return the selected category only.

Many thanks for all your hard work Alex!

Jonze
Quote Reply
Re: [Alex] How can I include a dropdown menu to search by category? In reply to
That's a handy piece of code, thanks! I did have to change 'cat_id' to 'catid' to get it to work.

This works great for doing a search, but is there a way to have a category pull down that will take the user to the static category page?

I would like to have a pulldown that lists ALL categories, and when they select a category and hit 'Submit' it would take them to the static category that they selected.

This may just be standard HTML code, but it's something I haven't done before so I'm not sure where to start.

Bryan

Last edited by:

BryanL: Mar 28, 2002, 9:45 AM
Quote Reply
Re: [Alex] How can I include a dropdown menu to search by category? In reply to
hi Alex

I did create the global and put the tag in my templates

But in the drop down menu, I have only the following options

All
$cat->{Name}

So I looked in the source code and I saw the following for the dropdown menu part ;

Links Only in:
<select name="catid">
<option value="">All</option>
sub {
my $cat_db = $DB->table('Category');
$cat_db->select_options ("ORDER BY Full_Name DESC");
my $sth = $cat_db->select ( { FatherID => 0 });
my $output = '';
while (my $cat = $sth->fetchrow_hashref) { $output .= "<option value='$cat->{ID}'>$cat->{Name}
</option>";
}
return $output;
}</select>

My global has not been treated...

I think I have missed something but I don"t have any ideas of what it can be...



ThanksWink



FMP
Quote Reply
Re: [fmp] How can I include a dropdown menu to search by category? In reply to
I have resolved my prob.....

don't need help anymore (...on that point Wink...)

thanks



FMP
Quote Reply
Re: [Alex] How can I include a dropdown menu to search by category? In reply to
Hi Alex,

Thank you for this nice feature.

Could you tell me what to do so only 5 of my top 8 categories appear in this dropdown menu? I have top categories like "shop" that redirect to a shop that does not use lsql, but a different shop building program. So obviously, that category ' s content is not in the lsql database.

I also have the gt forum listed in the top 8 categories, but the links sql search form script works with search.cgi, not gforum.cgi?do=search. Would it be easy to have the search "forum category" use one search script, and the search other lsql categories use search.cgi all on the same detailed search page in lsql? If not, I rather just not list the forum category in the top 8 like the shop.



Smilecheers.
Quote Reply
Re: [Alex] How can I include a dropdown menu to search by category? In reply to
Alex,

Great global Smile

Wondering how you'd get it to show all the categories, with their respective parents?
Quote Reply
Re: [Alex] How can I include a dropdown menu to search by category? In reply to
Alex,



what would it take to exclude from the dropdown menu a few root subcats?



Cheers.
Quote Reply
Re: [Alex] How can I include a dropdown menu to search by category? In reply to
The below code works great! But how can i change it to include all categories. Not just the top categories?

Thanks, Cat



Links Only in: <select name="catid"><option value="">All</option><%top_categories%></select>

and then in your globals add:

top_categories =>

Code:
sub {
my $cat_db = $DB->table('Category');
$cat_db->select_options ("ORDER BY Full_Name DESC");
my $sth = $cat_db->select ( { FatherID => 0 });
my $output = '';
while (my $cat = $sth->fetchrow_hashref) {
$output .= "<option value='$cat->{ID}'>$cat->{Name}</option>";
}
return $output;
}
Quote Reply
Re: [catlovette] How can I include a dropdown menu to search by category? In reply to
Hi,

Remove { FatherID => 0 } from the select.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Jonze] How can I include a dropdown menu to search by category? In reply to
hum.....

I don't know if I am using easy way or hard way, but it works like charm on my site. :)

Below is the code.... just make sure that you change the category as required.

Code:
<FORM name="search" method="get" action="<%db_cgi_url%>/search.cgi">
<p align="center">

<input name="query" size="18" maxlength="200">
<input type="Submit" value="Search" style="font-size:8pt">

<select size="1" name="catid">
<option selected value="">Entire Directory</option>
<%if category_id%>
<option value="<%category_id%>">Only this Category</option>
<%endif%>
<option value="3">ASP</option>
<option value="143">C and C++</option>
<option value="142">CFML</option>
<option value="144">Flash</option>
<option value="715">HTML</option>
<option value="145">Java</option>
<option value="146">Java Scripts</option>
<option value="1">Perl</option>
<option value="2">PHP</option>
<option value="147">Python</option>
<option value="148">Remotely Hosted</option>
<option value="149">Tools and Utilities</option>
<option value="150">Visual Basic</option>
<option value="151">XML</option>
</select> <a class="scriptsearch" href="<%db_cgi_url%>/search.cgi">Advanced</a>
</FORM>

Hope this helps :)

Vishal
-------------------------------------------------------

Last edited by:

NeedScripts.Com: Feb 17, 2003, 10:14 PM
Quote Reply
Re: [NeedScripts.Com] How can I include a dropdown menu to search by category? In reply to
The global will create a dynamic drop down menu, rather than yours, where it hard coded. Its quite a helpful global Smile

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] How can I include a dropdown menu to search by category? In reply to
I just added the global but the categories are in reverse alphabetical order!

Any way to get these to display alphabetically?

EX this is now

All
vans
trucks
cars
autos

I want

All
autos
cars
trucks
vans
Quote Reply
Re: [craven32] How can I include a dropdown menu to search by category? In reply to
Try changing;

Code:
$cat_db->select_options ("ORDER BY Full_Name DESC");

to

Code:
$cat_db->select_options ("ORDER BY Full_Name ASC");

That should do the trick Smile

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: [fmp] How can I include a dropdown menu to search by category? In reply to
Hi

I am having the same problem. Do you still remember how you resolved it?

Thank you in advance

Antoine