Jump to content

Please Help Improve My Search Facility


kamal213

Recommended Posts

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(); ?>

Link to comment
Share on other sites

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.

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.