i try compare temperatures of xml file database. it's comparing first of 7 datas. means while loop works on first pass, why?
$query = mysql_query("select * table"); //get temperatures databse foreach ($xml->forecast $forecast) { //just 1 pass (one forecast in xml) foreach ($forecast->time $time) { // 7 passes (7 dates in xml) echo $time['day'] . "<br />"; while ($row = mysql_fetch_array($query)) { //this loop works on first pass if ($row['mintemp'] <= $time->temperature['day'] && $time->temperature['day'] <= $row['maxtemp']) { echo $row['namekl'] . " | rating (" . $row['rating'] . ")" . "<br />"; } } echo "<br />"; } } i expect following result:
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) but results this:
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
the problem isn't foreach loops, it's in how you're using mysql. mysql_fetch_array returns results whole table first time call it, has nothing return on every other pass through loop...
Comments
Post a Comment