I want to search for a word+number if that SQL returns nothing, I will default it to a full LIKE search, is there any way to implement regex like this in SQL?
Example:
$queryWord = potato
- It should first search for potato+somenumber up to 4 digits
- It should return all matches with potato+somenumber
- If that fails, it defaults to a full search with wildcards on both sides
Like this:
$sql = "SELECT * FROM `words` WHERE `searchWord` LIKE '$queryWord+number';";
$result = mysqli_query($con, $sql);
if (mysqli_num_rows($result) == 0) {
$sql = "SELECT * FROM `words` WHERE `searchWord` LIKE '%$queryWord%';"; // full search
$result = mysqli_query($con, $sql);
// etc etc
}