How Can I Use LIKE and Equal Together in Mysql Select

Walrus :
include 'config.php';
$location_null = "";
$location = "%{test}%";
$stmt = $conn->prepare('SELECT * FROM students WHERE location LIKE ? AND location = ?');
$stmt->bind_param('ss', $location, $location_null); 
$stmt->execute();

This is my mysql codes. I wanna fetch datas from database for location like session and equal variable but this way's not working.

mrodo :

You have to replace the AND with an OR in your query to make both conditions work:

$stmt = $conn->prepare('SELECT * FROM students WHERE location LIKE ? OR location = ?');

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=14057&siteId=1