我尝试将 XML 文件的温度与我的数据库进行比较。但它只是比较 7 个数据中的第一个。这意味着 while 循环仅适用于第一遍,但为什么呢?
$query = mysql_query("SELECT * FROM table"); //get temperatures from databse
foreach ($xml->forecast as $forecast) { //just one pass (one forecast in the xml)
foreach ($forecast->time as $time) { // 7 passes (7 dates in the xml)
echo $time['day'] . "<br />";
while ($row = mysql_fetch_array($query)) { //This loop just works on the first pass
if ($row['mintemp'] <= $time->temperature['day'] && $time->temperature['day'] <= $row['maxtemp']) {
echo $row['namekl'] . " | Rating (" . $row['rating'] . ")" . "<br />";
}
}
echo "<br />";
}
}
我通常期望以下结果:
2013-07-19
Databse 1 | Rating (5)
Databse 2 | Rating (5)
Databse 3 | Rating (3)
2013-07-20
Databse 1 | Rating (5)
Databse 2 | Rating (5)
Databse 3 | Rating (3)
2013-07-21
Databse 1 | Rating (5)
Databse 2 | Rating (5)
Databse 3 | Rating (3)
2013-07-22
Databse 1 | Rating (5)
Databse 2 | Rating (5)
Databse 3 | Rating (3)
2013-07-23
Databse 1 | Rating (5)
Databse 2 | Rating (5)
Databse 3 | Rating (3)
2013-07-24
Databse 1 | Rating (5)
Databse 2 | Rating (5)
Databse 3 | Rating (3)
2013-07-25
Databse 1 | Rating (5)
Databse 2 | Rating (5)
Databse 3 | Rating (3)
但我的结果如下所示:
2013-07-19
Databse 1 | Rating (5)
Databse 2 | Rating (5)
Databse 3 | Rating (3)
2013-07-20
2013-07-21
2013-07-22
2013-07-23
2013-07-24
2013-07-25