ループの発生と継続などについて少し混乱しています。ユーザーの実際の特権とユーザーの特権を一致させ、新しいものと一致させる2つのSQLクエリがあります。ただし、新しい権限の一部がユーザーの権限と一致する場合は、SQL 挿入をスキップして次の権限に進みたいと考えています。
public static function insertPriveleges($user_id,$priveleges)
{
$ex = explode(",",$priveleges); // separated by commas
if(count($ex)>0)
{
$x = false;
foreach($ex as $i => $priv)
{
$check_user = mysql_query("SELECT * FROM users_access_codes WHERE user_id='$user_id'") or die(mysql_error()); // get user's current priveleges
while($check_data = mysql_fetch_array($check_user))
{
if($check_data['access_code']!=$priv)
{
//if it doesn't match, insert
$sql = "INSERT INTO users_access_codes (uaID,user_id,access_code) VALUES (NULL,'".$user_id."','$priv')";
}
}
}
}
}
ループ内で 2 つ以上のものを一致させる必要がある状況はほとんどありません。そのユーザーに二重の特権を与えないようにする必要があります。内側のループのどこかに 'continue' ステートメントがあるに違いないことはわかっていますが、どこにあるのかわかりません。