gpt4 book ai didi

php 循环 mysql 帮助

转载 作者:行者123 更新时间:2023-11-29 15:07:39 26 4
gpt4 key购买 nike

如果 $walk_jail 不为空,我试图让它停止显示其余部分

1) $walk_jail 为空

2) $walk_jail 为空

3) $walk_jail 为空

4) $walk_jail 不为空

停止显示其余部分。

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

谢谢

最佳答案

我猜您正在寻找 break; statement ,这会让你脱离循环。

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

关于php 循环 mysql 帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1656230/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com