Jump to content

While (condition) Help


dzhax
 Share

Recommended Posts

I am opening a while and inside the while i have an if statement. If that statement proves true I want to exit the while. Is this possible and how? Couldn't find it on the main w3schools website.

$sbanned = mysql_query("SELECT * FROM shoutbans");	while ($sban = mysql_fetch_row($sbanned)){		if ($sban['user'] == $_SESSION['user'])			$usrBanned = 'yes';	}	if ($ustBanned == 'yes'){			"Show information"	} else {		echo 'This section is off limits, you are banned from using it.';	}

Or if you know of a better way to check if the session user is in the shoutbans table.Basically i made a shout box but I do not want it to show if the logged in user is banned from it.

Edited by dzhax
Link to comment
Share on other sites

First stop, enclose your condition's body with "{}". And second, you can use the break statement.

if ($sban['user'] == $_SESSION['user']) {			$usrBanned = 'yes';			break;}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...