Hey all, this is my first question here so i hope its not a dumb one lol.... im working on a site that has mulitple ways to query the DB the one that has me stumped is were the user types in the the name they are searching for...this would be easy but as ive already probably misspelled something in this post im taking that under consideration and im trying for the first time to use a LIKE statment and its not quit working correctly. if i type in the first letter of something im trying to query then i get results on every thing that has that letter or if i type in the name exactly as it appears in the DB i get the right response but again this wouldnt be an isssue if every one new how every thing was spelled. but if i type it in close but not right i get nothing... take a look and hopefully its something silly i missed
require ('sessions.php'); foreach($_SESSION as $key => $value) { $key = $value; } $query = "SELECT * FROM database WHERE name LIKE'%$name'"; $result = mysql_query($query) or die ("couldnt execute query." . mysql_error()); while ($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['type'] . "</td><td>" . $row['name'] . "</td><td>" . $row['address'] . "</td><td>" . $row['phonenumber'] . ; } thanks for taking a look
Look up Full Text Search.
One other option you could try is the following:
SELECT * FROM database WHERE name LIKE'%$name' or name Like '$name%' ";
But full text search would get you better results, typically.