netpants Posted October 31, 2007 Share Posted October 31, 2007 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>"; } ?> Quote Link to comment Share on other sites More sharing options...
fenway Posted October 31, 2007 Share Posted October 31, 2007 switch LIKE '$street%' to = '$street'. Quote Link to comment Share on other sites More sharing options...
Barand Posted October 31, 2007 Share Posted October 31, 2007 Seems an odd thing to do when ...and the street can come up with anything similar. Quote Link to comment Share on other sites More sharing options...
netpants Posted October 31, 2007 Author Share Posted October 31, 2007 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. Quote Link to comment Share on other sites More sharing options...
fenway Posted October 31, 2007 Share Posted October 31, 2007 Did you try my suggestion (i.e. no wildcards)? Quote Link to comment Share on other sites More sharing options...
netpants Posted October 31, 2007 Author Share Posted October 31, 2007 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()); Quote Link to comment Share on other sites More sharing options...
Barand Posted October 31, 2007 Share Posted October 31, 2007 If you want similar stuff for street entry use street LIKE '$street%' Quote Link to comment Share on other sites More sharing options...
netpants Posted October 31, 2007 Author Share Posted October 31, 2007 Yes but how do i incorporate it where the syntax would be correct Quote Link to comment Share on other sites More sharing options...
Barand Posted October 31, 2007 Share Posted October 31, 2007 <?php $result = mysql_query("SELECT * FROM coords WHERE street LIKE '$street%' AND city='$city' AND county='$county' AND sfx='$sfx'") or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
netpants Posted October 31, 2007 Author Share Posted October 31, 2007 Great that worked. Thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.