I want to use the MATCH AGAINST query instead of like. I want to search in my database for a certain value whose attribute is not specified (like WHERE id = 2045). I have a search bar like google in my site and I want to write for example: 2045 or John and this gives me all about it. I dont want to search only for years ou names. I already have this for a specific attribute as name:
$name = $_POST["name"];
$sql="SELECT id, name, city FROM student WHERE name LIKE '".$name."%'";
But what I want is something with the MATCH AGAINST query. I don't know how to do that... This is what I have:
$sql ="SELECT id, name, city FROM student WHERE MATCH(id, name, city) AGAINST ('".$name."%')";
Here, I want my $name to be something random that I wrote in my search bar. Thank you
Do you've any specific reason not using multipe LIKE
with OR
?
$name = $_POST["name"];
$sql="SELECT id, name, city FROM student
WHERE id LIKE '".$name."%'" OR
name LIKE '".$name."%'" OR
city LIKE '".$name."%'";
Another way to do it using CONCAT()
,
$sql="SELECT id, name, city FROM student WHERE CONCAT(id,name,city) LIKE '".$name."%'";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.