Gossamer Forum
Home : Products : Gossamer Links : Discussions :

search on zipcode and display a category zone page.

Quote Reply
search on zipcode and display a category zone page.
Hello ALL,

Ehm, i will try 2 explain what my question is:

I have created a new table called: zip
with:

- field zipcode
- field zone

Data of table zip:
Zipcode Zone
1234 1
4243 1
6500 2
8600 1
9000 2


Let's say we have a search field called zip_zipcode.

If a visitor do a search like entering zip_zipcode = 6500, links have to display category page zone2.
Other example: zip_zipcode search is 8600 it have to display category page zone1 and so on.

I don't wanna do this dynamic but static!

I have data in table links like:
url,title,category (i allways select 2 categories. 1 category with a logical name and 1 with the zone name).

Any idea's how to do this? (hope it's clear what i am asking?)

Allready thanks.

Regards startpoint.

Last edited by:

startpoint: Sep 18, 2001, 3:08 AM
Quote Reply
Re: [startpoint] search on zipcode and display a category zone page. In reply to
Hi,

Well you are going to need some custom code. =) You basically want a script that will take in a zipcode, turn that into a zone number, and then print a category page. What I would do is add a zipcode.html template and then call:

page.cgi?p=zipcode&zipcode=1234

Then, add a global:

zipcode_lookup =>
Code:
sub {
my $tags = shift;
my $zipcode = $tags->{zipcode} or return "No zipcode entered!";
my $zip_db = $DB->table('zip');
my ($zone) = $zip_db->select ( { Zipcode => $zipcode })->fetchrow_array;
$zone or return "No matching zone!";
my $cat_db = $DB->table('Category');
my ($cat_id) = $cat_db->select ( ['ID'], { Name => "zone$zone" })->fetchrow_array;
$cat_id or return "Zone: $zone does not match a category!";
return Links::Build::build ('category', { id => $cat_id, nh => 1 });
}
What that chunk of code does basically is:

1. Get the zipcode that was passed in.
2. Query the zip table and find out what zone that is for.
3. Query the Category table and find the category id for that zone
4. Print the category page for the matching id.

All you need to do now is put <%zipcode_lookup%> on your template page and thats it!

Let me know if some of that doesn't make sense.

Cheers,

Alex
--
Gossamer Threads Inc.