I have a problem with showing record if in column values are in set.
My code looks like this but it only works if value is one language.
function showSets($db,$lang)
{
echo "dane z database: <br>";
$sq = "SELECT * FROM clients WHERE Languages = '$lang'";
$result = $db -> select($sq,['FamilyName','Name','Age','Country','Email','Languages','Payment']);
echo $result;
}
CodePudding user response:
You can use find_in_set
:
SELECT *
FROM clients
WHERE FIND_IN_SET($lang, languages)
Side note:
Using string interpolation with $lang
like your snippet shows probably leaves your code vulnerable to SQL injection attacks.
You should probably use a prepared statement instead.