문제

This is the SQL code I am using:

For some reason it deletes all records for the UserID but does not take into account the NOT IN array. I need it to delete only if the user ID = the current user AND the courseID of that user is not in the array..

mysql_query("DELETE FROM tblLinkUserCourse WHERE ((UserID=$CurrentUserID) AND (CourseID NOT IN ({$new_array})))");
도움이 되었습니까?

해결책

1) Remove all unnecessary () from query.

2) Check $new_array contains all your course_id or not and constructed as string. If not constructed as string and comma separated use this code.

$new_array = implode(',', $new_array);
mysql_query("DELETE FROM tblLinkUserCourse WHERE UserID=$CurrentUserID AND CourseID NOT IN ({$new_array})");

다른 팁

Is $new_array PHP array or string prepared for query? If it is array you should use:

$new_array = implod(',', $new_array);
mysql_query("DELETE FROM tblLinkUserCourse WHERE ((UserID=$CurrentUserID) AND (CourseID NOT IN ({$new_array})))");

Try:

$new_array  = "'".implode("', ", $new_array)."'";
$sql        = "DELETE FROM tblLinkUserCourse WHERE ((UserID=$CurrentUserID) AND (CourseID NOT IN ({$new_array})))";
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top