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