You can check if there's a match like this: (OOP)
$sql = $dbconnection->query('SELECT * FROM table_name WHERE interests = $interests');
if($sql->num_rows > 0) {
// do whatever you want to do when there is a match
} else {
echo 'No match has been found!';
exit();
}
Procedural style:
$sql = mysqli_query($dbconnection, 'SELECT * FROM table_name WHERE interests = '.$interests);
if(mysqli_num_rows($sql) > 0) {
// do whatever you want to do when there is a match
} else {
echo 'No match has been found!';
}
I don't know if you're familiar with prepared statements, but I do recommend you using them.
OOP & Prepared statements:
$sql = $dbconnection->prepare('SELECT * FROM table_name WHERE interests = ?');
$sql->bind_param('s', $interests);
$sql->execute();
$sql->store_result();
if($sql->num_rows > 0) {
// do whatever you want to do when there is a match
} else {
echo 'No match has been found!';
exit();
}
I also recommend you using MySqli instead of MySql, since MySql is deprecated for PHP7 and MySqli does support Prepared Statements and MySql does not. (When should I use MySQLi instead of MySQL?)
I hope this helped you.
Edit
You need to fetch all rows.
$sql = $dbconnection->query('SELECT * FROM table_name);
$result = $sql->get_result();
$row = $result->fetch(MYSQLI_ASSOC);
$result->free_result();
And then you search in the $row
variable for a match.
I recommend you using an array for $interests
, because it's easier to search in the indexes. (You can use array_search / in_array)