kamal213 Posted October 10, 2011 Share Posted October 10, 2011 Hi Guys, I have a simple PHP search facility (Below this post) for my customer system which uses a input form so users enter a customers name/telephone/address and it echos the result. Its great but I observed as my customer table got bigger the search got less accurate, what i mean is when you search for mr test is give ur mr test along with mr andy and ms danielle. Its ok but those any know how to make my search code better or can y'all help me with a better php search script. Thanks. <?php $query=$_GET['query']; $query= str_replace("'","",$query); // Change the fields below as per the requirements $db_host="localhost"; $db_username="root"; $db_password=""; $db_name=""; $db_tb_name="customer"; $db_tb_atr_name="c_name"; $query= str_replace("'","",$query); //Now we are going to write a script that will do search task // leave the below fields as it is except while loop, which will display results on screen mysql_connect("$db_host","$db_username","$db_password"); mysql_select_db("$db_name"); $query_for_result=mysql_query("SELECT * FROM customer WHERE c_name like '%".$query."%' OR c_telephone like '%".$query."%' OR c_address like '%".$query."%'"); while($row=mysql_fetch_assoc($query_for_result)) { $c_id = $row['c_id']; $c_name = $row["c_name"]; $c_address = $row["c_address"]; $c_postcode = $row["c_postcode"]; $c_city = $row["c_city"]; $c_telephone = $row["c_telephone"]; $c_email = $row["c_email"]; $salesman = $row["salesman"]; echo '<table width="100%" border="0"> <tr> <td><a href="customers.php?id=' . $c_id . '"> ' . $c_name . '</a> - ' . $c_address . ' - ' . $c_city . ' - ' . $c_telephone . '• <a href="customer_edit_index.php?pid=' . $c_id . '">edit</a><br /><br/></td> </tr> </table>'; } mysql_close(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/248789-please-help-improve-my-search-facility/ Share on other sites More sharing options...
titan21 Posted October 10, 2011 Share Posted October 10, 2011 Been thinking about this and I can't think why "mr test" should give rise to "ms danielle". Can you provide the data that is the database for "ms danielle"? We might be able to see if there is something matching in that record to "mr test" which is why it is appearing. I can't think of any other reason why this may be happening. Quote Link to comment https://forums.phpfreaks.com/topic/248789-please-help-improve-my-search-facility/#findComment-1277667 Share on other sites More sharing options...
kamal213 Posted October 10, 2011 Author Share Posted October 10, 2011 Yes there is something matching - they have the same address. Quote Link to comment https://forums.phpfreaks.com/topic/248789-please-help-improve-my-search-facility/#findComment-1277678 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.