0

我正在尝试获取每一行的结果并一次打印出一个,以便我最终可以将它们放在自己的特定变量中,但它不起作用。谁能看到我做错了什么?它只是进入打印第一行的无限循环。我知道总共有 4 行。

$scores_query = mysql_query("SELECT Day, Time, AM_PM,
Away, 
case when Away_Score is null then '@' else Away_Score end as Away_Score, 
Home,
case when Home_Score is null then '' else Home_Score end as Home_Score
FROM `NFL_Games` WHERE Week=6 
order by
(case Day
 when 'Thu' then 1
 when 'Sat' then 2
 when 'Sun' then 3
 when 'Mon' then 4
 else 5 end), 
 Day, Time ASC");
 $count = mysql_num_rows($scores_query);
 echo "Hellloooo" . $count;
while($results = mysql_fetch_array($scores_query)) {
  for($x = 1; $x <= $count; $x++) {
    /*echo $results['Day'] . "__" . $results['Time'] . "__" . $results['AM_PM'] . "__" . $results['Away'] . "__" . $results['Away_Score'] . "__" . $results['Home'] . "__" . $results['Home_Score'];
    echo "<br/>";*/
    /*echo (Day, Time, AM_PM, Away, Away_Score, Home, Home_Score);*/
    if ($x = 1) {
    echo $results['Day'] . "__" . $results['Time'] . "__" . $results['AM_PM'] . "__" . $results['Away'] . "__" . $results['Away_Score'] . "__" . $results['Home'] . "__" . $results['Home_Score'];
    echo "<br/>";
    } else if ($x = 2) {
    echo $results['Day'] . "__" . $results['Time'] . "__" . $results['AM_PM'] . "__" . $results['Away'] . "__" . $results['Away_Score'] . "__" . $results['Home'] . "__" . $results['Home_Score'];
    echo "<br/>";
    } else if ($x = 3) {
    echo $results['Day'] . "__" . $results['Time'] . "__" . $results['AM_PM'] . "__" . $results['Away'] . "__" . $results['Away_Score'] . "__" . $results['Home'] . "__" . $results['Home_Score'];
    echo "<br/>";
    } else if ($x = 4) {
    echo $results['Day'] . "__" . $results['Time'] . "__" . $results['AM_PM'] . "__" . $results['Away'] . "__" . $results['Away_Score'] . "__" . $results['Home'] . "__" . $results['Home_Score'];
    echo "<br/>";
    } else {
    break;
    }
  }
}
4

2 回答 2

0

你为什么在你的while循环中做一个for循环?由于您有if ($x = 1),$x每次运行 for 循环时都将设置为 1,因此它将无限运行,并且永远不会退出 for 循环并第二次运行 while 循环。

由于您没有$x在 for 循环中做任何事情,只需执行您的 while 循环,它将遍历所有 4 行

while($results = mysql_fetch_array($scores_query)) {
    echo $results['Day'] . "__" . $results['Time'] . "__" . $results['AM_PM'] . "__" . $results['Away'] . "__" . $results['Away_Score'] . "__" . $results['Home'] . "__" . $results['Home_Score'];
    echo "<br/>";
}
于 2013-10-12T03:58:59.427 回答
0

看看你的 if 子句。您真的想在 if 子句中为 $x 赋值吗?

如果没有,请以这种方式编写 if 子句: if($x == 2)

希望我明白你的问题。

于 2013-10-12T03:17:57.560 回答