I'm a little confused about breaking out and continuing out of loops etc. I have 2 SQL queries that match user priveleges against the user's actual priveleges with the new ones put it. However, if some of the new priveleges match the one the user has, I want to skip the SQL insert and move on to the next one:
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')";
}
}
}
}
}
I almost never have a situation that needs to match more than two things in loops. I need to make sure I don't end up with double priveleges for that user. I know there must be a 'continue' statement somewhere in the inner loop, but not sure where.
$x = false;?continue 2should do the trick, it skips back the top of yourforeach.continue 2whileloop and the end of theforeachloop, then yes :)