gpt4 book ai didi

php - 循环直到变量达到 0

转载 作者:行者123 更新时间:2023-11-29 13:05:59 24 4
gpt4 key购买 nike

我有一个查询,它使用计数给出出现次数,请参见下文:

$query = "SELECT COUNT(a.market_id) AS winners, a.winner, 
a.twitter_pubstatus, a.market, a.racetime, a.racecourse, b.course, b.horse,
b.type, b.racetime FROM results a INNER JOIN bets b ON a.racecourse = b.course
WHERE a.twitter_pubstatus = 0 AND a.market = '$win' AND
b.type = '$userwin' AND a.winner = b.horse;";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result);
$checkWinners = $row['winners'];

echo $checkWinners;

例如,这将返回 11。我现在有一个 IF 语句:

<?php if ($checkWinners > 1) { ?>

DO THIS

<? } else { ?>

DO THIS INSTEAD

<? } ?>

现在它运行一次就很好了。我希望它循环遍历,所以 11 然后遍历第一位,然后需要它是 10 并遍历直到它达到 0,然后停止。

如何做到这一点? while 循环?感谢帮助

最佳答案

是的,你可以用 while 循环来做到这一点。基本逻辑是这样的:

$c = 10;
while ($c > 0) {
// do something
$c--;
}

但如果我不得不猜测,我想也许你真正想要的是这样的:

$query = "SELECT COUNT(a.market_id) AS winners, a.winner, 
a.twitter_pubstatus, a.market, a.racetime, a.racecourse, b.course, b.horse,
b.type, b.racetime FROM results a INNER JOIN bets b ON a.racecourse = b.course
WHERE a.twitter_pubstatus = 0 AND a.market = '$win' AND
b.type = '$userwin' AND a.winner = b.horse;";
$result = mysql_query($query) or die(mysql_error());

while ( $row = mysql_fetch_array($result) ) {
$checkWinners = $row['winners'];
echo $checkWinners . '<br/>';
}

这将循环查询从返回的所有行。

关于php - 循环直到变量达到 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22695387/

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