php - Live search using AJAX: How to implement the server-portion -


I am creating a simple case management system for agents of my company and I thought it was implementing some form

So, here's the situation, and a question:

I have a table (or, rather, an view ) with the following columns :

  1 First name, 2. Last name, 3. Phone, 4. Category 5. Owner, 6. Status, 7. Manufacturer (For each of our sanitary ware, St or (n) varchar or 'any other representation of string')   

I can definitely search for each column and then present the result, but know about the script There will be no way to do what the result (or 'suggestions') will be most relevant to the user.

So, how do you actually implement an live search from the point of view of the server?

I definitely like to search through SQL, but I can not use stored procedures, possibly even though it is possible, it is not limited.

Edit: (for clarification): I want to find my column and return the result for user searches The closest and most relevant (similar to Google). Preferably via SQL, but if possible, PHP is possible to use it.

Firstly you can pass a URL to a request for you. It is important that as much as possible Load fewer resources. Since you are going to do just one query and return a response, so it would be good to avoid booting a large part of your framework (if you are using one). This is important because you want to speed up the search prompt.

Will the URL be example.com/search/searchterm or example.com/search? Searchterm = searchterm .

That url should go to a script where you read the searchers and search for it. Whether you are using a MySQL database, a SOLR server or something else, does not really make any difference (code wise. MySQL is not optimized for full text search, but this is a complete other topic)

The result of searchterm can be returned as JSON encoded string. It is easily handled in JavaScript (I think the customer side implementation of your problem will be used by Javascript)

The way MySQL can be something like this:

search.php $ searchTerm = real_escape_string ($ _GET ['searchterm']); $ Sql ​​= "Select 'Last name' from 'TableName', where '%' $ SearchTerm"% '"like' Last Name '; // Use the results of the query to create a piece of HTML or return a JSON encoded array and build the HTML client side. $ Output = .... header ('content-type: app / jason'); Echo PBJSone :: Encoding ($ output);

Edit:

After understanding the real question from Henes, I had suggested to check which columns were the best match. This function looks at the difference between two strings and returns it, you can use it to see which columns were the closest match and use it to decide what you will return.

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -