Select where not equal to multiple values of keys of associative array
associative-array, mysql, php, select
Solution
remove `foreach`loop and use `NOT IN` comparision in MySQL:
$query="
SELECT hobbyid,hobbyname
FROM hobbies
WHERE hobbyid NOT IN (" . implode(',', $_SESSION['hobby_id']) . ")
";
Problem
I had made three tables. Table1=users.And the column names are userid (auto_increment) and username. Table2=hobbies. column names are hobbyid (auto_increment) and hobbyname. Table3=users_hobbies. column names are FK_userid and FK_hobbyid. Now hobbyname has cricket,football,volleyball. During sign-up user selects only cricket and football and I store it in $_SESSION['hobby_id'] associative array. But in profile he/she wants to add some more hobbies. So I want to display list of hobbies which are not equal to $_SESSION['hobby_id']. This , ofcourse didn't work: ``` foreach($_SESSION['hobby_id'] as $k=>$v) { $query="select hobbyid,hobbyname from hobbies where hobbyid!= $v"; } Output was football,volleyball and cricket,volleyball....but i wanted only volleyball ``` So i want that ``` $query="select hobbyid,hobbyname from hobbies where hobbyid!=(multiple values of session hobby id)"; ``` What code will I have to enter to get desired result(only volleyball)?