I created a Movie Library Database in MySQL. I also created a PHP REST API for getting data as JSON, That drives my app.
Currently, The movie search works using the LIKE Statement In MySQL. But it doesn't provide a broad elastic search
For instance, If a movie name is
THE AMAZING SPIDERMAN I wan't to get the record by any of the searches like
- the
- amaz
- spider man
- the spider man
- amazing the
- amaz spider
I don't have SSH and Composer access on my host. How should I change my SQL Query to return results like this. I thing to go for REGEX? What kind of a REGEX match here?
My current query is
$q=$_POST["q"];
$sql = "SELECT * FROM AudioReg WHERE Name LIKE '$q%';
Which works like normal search only. My complete PHP code is
<?php
include "Database.php";
$q=$_POST["q"];
$sql = "SELECT * FROM AudioReg WHERE Name LIKE '$q%' ORDER BY RAND()";
$result = mysqli_query($connection, $sql);
$json=array();
while($row =mysqli_fetch_assoc($result))
{
$json[]=$row;
}
echo json_encode($json);
mysqli_close($connection);
?>