开发者

php loops mysql Help

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_t开发者_StackOverflowxt 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


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>";
  }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜