How to not only break from switch statement but exit program?

Hi,
I am querying a database, running a switch statement and should the variable equal a couple of the possibilities, leave the switch and exit the program, otherwise leave the switch but continue on through the program.

With regards to the code below:
For values: "Not Banned" and "Slow Down" I want it to leave the switch and continue on (works fine).

But for "Busy Signal" and "Reject Call", I'm trying to get it to do what is in the case and then just exit the whole thing. What is happening is it executes the element in the case statement but continues on. How do I kill the program just for those two possibilities?

 
// Check for Ban
$result = mysql_query("SELECT Phone FROM ban WHERE Number_noformat = '$FromCaller' AND account_id = '$account_id' LIMIT 1");

if(mysql_num_rows($result)!=0){
	while ($row = mysql_fetch_assoc($result)) {
	$phoneban = $row["Phone"];
	
	switch ($phoneban){
	
		case "Not Banned":
		break;
		
		case "Slow Down":?>
		<Pause length="12"/>
		<?php
		break;
	
		case "Busy Signal":?>
		<Reject reason="busy" />
		<?php
		break;
	
		case "Reject Call":?>
		<Reject />
		<?php
		break;
		}
		
}
}

Open in new window


*Lastly any suggestions how to improve my code are always welcome :)
LVL 1
tjyoungAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Lukasz ChmielewskiCommented:
just use exit(); instead of break;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
eriksmtkaCommented:
the php function "exit()" actually stops the script from processing further instructions
0
tjyoungAuthor Commented:
thanks I didn't realize you can swap out break with exit
0
eriksmtkaCommented:
suggested improvement...

i don't usually break out of PHP to print text.. especially in case like this where you don't have much to print anyway and formatting isn't really necessary...

switch ($phoneban){
	
		case "Not Banned":
		break;
		
		case "Slow Down":
                echo '<Pause length="12">';
		break;
	
		case "Busy Signal":
		echo '<Reject reason="busy" />';
		break;
	
		case "Reject Call":
		echo '<Reject />';
		break;
		}

Open in new window


Also.. the use of switch/case is kind of a religious argument.  A lot of people don't like them, i for don't have an opinion, but using if/elseif/then is perfectly acceptable:

if ($phoneban == "Not Banned") {
...
} elseif ($phoneban == "Slow Down") {
...
} elseif ($phoneban == "Busy Signal") {
...
} elseif ($phoneban == "Reject Call") {
...
}

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.