0

I am trying to make it stop showing the rest if $walk_jail is not empty

1) $walk_jail is empty

2) $walk_jail is empty

3) $walk_jail is empty

4) $walk_jail is Not empty

Stop showing the rest.

$walk = 15;

for ( $counter = 1; $counter <= $walk; $counter += 1) {

$result= mysql_query("SELECT * FROM walk_txt") or die (mysql_error());
$walk_numrows = mysql_num_rows($result);
$random_walk = rand(1,$walk_numrows);

$getfl = mysql_query("SELECT * FROM walk_txt WHERE id='$random_walk'");
$showfinfo = mysql_fetch_array($getfl);

$walk_txt = $showfinfo['txt'];
$walk_jail = $showfinfo['jail'];
$walk_hp = $showfinfo['hp'];
$walk_money = $showfinfo['money'];
$walk_item = $showfinfo['itemid'];

if($walk_jail){
echo "$counter) <span class='bad'>$walk_txt</span><br>";
}elseif($walk_money){
echo "$counter) <span class='win'>$walk_txt</span><br>";
}elseif($walk_item){
echo "$counter) <span class='win'>$walk_txt</span><br>";
}elseif($walk_money == 0 && $walk_jail == 0 && $walk_hp == 0){
echo "$counter) $walk_txt<br>";
}

Thank you

1 Answer 1

1

I guess your looking for the break; statement, which will drop you out of a loop.

$walk = 15

for ( $counter = 1; $counter <= $walk; $counter += 1) {

  ....    

  if($walk_jail){
    echo "$counter) <span class='bad'>$walk_txt</span><br>";
    break; // ** this will drop out of the loop
  }elseif($walk_money){
    echo "$counter) <span class='win'>$walk_txt</span><br>";
  }elseif($walk_item){
    echo "$counter) <span class='win'>$walk_txt</span><br>";
  }elseif($walk_money == 0 && $walk_jail == 0 && $walk_hp == 0){
    echo "$counter) $walk_txt<br>";
  }
}
Sign up to request clarification or add additional context in comments.

1 Comment

You can also use break 1; etc to break out of various parts of the loop - just a little tip :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.