Forum Moderators: coopster

Message Too Old, No Replies

Getting region matches

Trying to find a way to easily do regions in php

         

togethercomms

9:13 am on Jan 27, 2010 (gmt 0)

10+ Year Member



Hi All,
I am trying to find a way to easily match regions with places within a search.

My client wants to display different regions and for the search to find a county/city/town to that region.

Example:

The user inputs

Title: Assistant
Salary (Min): £13,000
Salary (Max): £25,000
Location: South-west

and the results should be everything within the south-west area
I am using MySQL.

Many Thanks

JS_Harris

1:14 pm on Jan 27, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



In general people search in their immediate area so going with zip codes would be easiest, scripts exist to do this already and have features such as "distance from" any zip code.

The next best option is to store data by State and possibly city, many searchers will want to specify one and/or both in any search.

Just my 2 cents but "South West" may be too vague. If it's a must to go with SW you'll want to set up a SW table, along with a NW, NE and SE table, and have results search only the appropriate table.

I can't provide code without seeing what you have in place.

togethercomms

2:26 pm on Jan 27, 2010 (gmt 0)

10+ Year Member



all i have at the moment is the job title, salary, and location which is specified, london or surrey etc.

Hope this helps

rocknbil

8:25 pm on Jan 27, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You're definately going to need one of the two. The first, although it may seem to be more work, would certainly be more reliable.

table jobs
id¦title¦salary¦city¦province¦region

table regions
id¦region

table cities
id¦title¦province¦region

Might even need provinces too, to fully normalize. The regions, cities, etc. are all stored in the jobs table by ID as integers:

table jobs
id¦title¦salary¦city¦province¦region
1¦Head Janitor¦25000¦123¦45

so your region select list would be like

...
<option value="45">South West</option>
...


$where=NULL;
if (isset($_POST['region']) and ($_POST['region'] > 0)) {
if ($where) { $where .= ' and'; }
$where .= " region=" . $_POST['region'];
}
}
$query = "select * from jobs";
if ($where) { $select .= " where $where"; }

The other solution is as mentioned, use some connection to say, the G. maps API to get what you're looking for, but this makes it unreliable on a couple points: it's an external service, and is largely driven by Javascript.