Basically I have a search query, which works fine if I’m using it with $_GET, but I want to use $_POST for one of them (then return with json). However I’m unsure how to accomplish this so that the search will look at each word individually…
Here’s my search query…
SELECT DISTINCT(auto), user_id, username, first_name, last_name, email, sex, active, ppic, time_zone, adult_filter, ((CASE WHEN `username` LIKE '%$search%' THEN 2 ELSE 0 END) + (CASE WHEN `first_name` LIKE '%$search%' THEN 1 ELSE 0 END) + (CASE WHEN `last_name` LIKE '%$search%' THEN 1 ELSE 0 END)) AS relevance
FROM users, network
WHERE `username` LIKE '%$search%' OR
`last_name`LIKE '%$search%'
OR `first_name` LIKE '%$search%'
ORDER BY relevance DESC, username LIMIT 5
So basically, all I need to do is make $search = $_POST['search'] functional with this query… can anyone tell me how this is accomplished?
EDIT:
Looks like I can just use $.get… (which makes a lot of sense) rather than $.post (which is what I was used to) and get the same result. Feel free to correct me if I’m wrong, however I’m going to try this out and see how it goes.
The short answer is that you shouldn’t do this.
Now, the long answer …
Why would you want to use
$_POSTfor a read request in the first place? Let me introduce you to the concepts of safety and idempotence in the context of HTTP.The HTML 2.0 spec says:
A bit about HTTP GET
The HTTP verb
GETwas specifically created to retrieve a resource without any possibility of changing it. What I mean is that it’s safe. It doesn’t cause any side effects. AGETrequest in your case should be used to get data from a database and display it. Existing HTML pages, images requests, database searches, etc. … these are all safe requests that should be made withGET.Meanwhile, idempotent means that executing the request 724 times will have the same effect as doing it once. An idempotent request might create something in a database the first time, but it won’t do it again or it will just return the reference to it the next time around.
The HTML spec continues …
So, in summary, please understand that you shouldn’t use
POSTto perform safe, read-only operations.