Jump to content

Return Results From A Mysql Database Dependent On Town Entered


ianhaney

Recommended Posts

Hi

 

I am bit stuck, I want to return results from a mysql database when a user enters their town or postcode in for example below

 

they enter in their town or post code and a list of area managers is displayed closest to their town or postcode along with their contact number

 

Is that possible

 

Thank you

 

Ian

Link to comment
Share on other sites

Hi Muddy_Funster thank you for the reply

 

I think it will be more the PHP that has me stuck as entering the data should be fairly easy to do, am I right in doing something like the following in the mysql database

 

name

contactnumber

 

the page I want to display the results will look like the following

 

Area Manager: name or manager

Contact Number: contact phone number

Link to comment
Share on other sites

Yes sorry, my idea is based purely on postal areas, if wont give you the closest person to you, it will just provide results in that postal area, in a sense imitating the functionality of closest too. The problem is, if there is no one in that postal area it will return nothing instead of searching the next postal area.

 

You would need to provide further information, co-ordinates and the lark and a way of searching co-ordinates within a radius of 10 miles etc. Sounds like a big job!

Link to comment
Share on other sites

You basically want to use the function the developer is showing you called:

 

calc_postcode_seperation($pcodeA,$pcodeB)

 

You will then need to compare the postcode the user entered with all of your entries in your database, using a loop, then use an if statement to see if they are located less than 10km or whatever from the postcode entered by your user andif they are, add the details to an array and then output the data collected in the array onto your page at the end.

 

The developer provides you with an sql file with all of the postcode details. I am assuming you are located in the UK?

Link to comment
Share on other sites

I have got the 0 displaying now

 

How do I get results to display what the users chooses for example I have a input text field and typed a town in but is still displaying all the records from the database

 

The coding I have is below

 

<html>  
<head><title>Page Results</title></head>  
<body>  
<?php  
$database="";  
mysql_connect ("", "", "");  
@mysql_select_db($database) or die( "Unable to select database");  
$result = mysql_query( "SELECT * FROM managers" )  
or die("SELECT Error: ".mysql_error());  
$num_rows = mysql_num_rows($result);  
print "There are $num_rows records.<P>";  
print "<table width=400 border=1>\n";  
while ($get_info = mysql_fetch_row($result)){  
print "<tr>\n";  
foreach ($get_info as $field)  
print "\t<td><font face=arial size=1/>$field</font></td>\n";  
print "</tr>\n";  
}  
print "</table>\n";  
?>
<form action="viewall.php">
Town
<input type="text">
<input type="submit" name="send" value="Search">
</form>
</body>  
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.