Jump to content

[SOLVED] exact matches


netpants

Recommended Posts

This is what I have, I am trying to do a query from a form. In my select from part of the code, what do i need to change in there so that it looks for the City to be exactly what is entered, the County is exactly what is entered and the street can come up with anything similar. I would appreciate your help 

 

 

// connect and select the database 
   $conn = mysql_connect($host, $user, $password) or die(mysql_error()); 
   $db = mysql_select_db($dbName, $conn) or die(mysql_error()); 
$county = $_POST['county'];
$city = $_POST['city'];
$street = $_POST['street'];
$zip= $_POST['zip'];
$cp = $_POST['cp'];


// Insert a row of information into the table "example"
$result = mysql_query("SELECT * FROM coords WHERE street LIKE '$street%'") 
or die(mysql_error());   

echo "<table border='0'>";
echo "<tr> <th>County</th><th>City</th><th>Address</th><th></th><th></th><th></th><th>Coordinates</th> </tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table 
echo "<tr><td>"; 
echo $row['county'];
echo "</td><td>"; 
echo $row['city'];
                echo "</td><td>"; 
echo $row['number'];
echo "</td><td>";
                echo $row['cp'];
echo "</td><td>";
                echo $row['street'];
echo "</td><td>";
                echo $row['sfx'];
echo "</td><td>";
                echo $row['coordinates'];
echo "</td></tr>";  
}
?>

Link to comment
Share on other sites

Ok I have a form its layed out like this.

 

County:        City:            Street:            Zip:

 

People are going to enter in information in this form and get results from my database. When they type in county, city,street, and zip it will look in my database and bring up whatever matches exactly what they typed in. There is a column for eatch of those fields in my table i call coords. So if they type County: Happy  City: Unhappy City  Street: Boringsville  Zip: 65050  , it would take that information and look for an exact match in my database and display it.

Link to comment
Share on other sites

this is what I did and it seemed to work, i just wont get similar stuff to whatever is entered in the street name filed.

 

$result = mysql_query("SELECT * FROM coords WHERE street='$street' AND city='$city' AND county='$county' AND sfx='$sfx'") 
or die(mysql_error());

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.