$php_mysql$ Posted October 4, 2010 Share Posted October 4, 2010 here is the code i edited <html> <head> <title>API</title> </head> <body><?php$xml = simplexml_load_file('http://www.google.com/ig/api?weather=jakarta');$information = $xml->xpath("/xml_api_reply/weather/forecast_information");$current = $xml->xpath("/xml_api_reply/weather/current_conditions");$forecast_list = $xml->xpath("/xml_api_reply/weather/forecast_conditions"); echo "<h1>print $information[0]->city['data']; </h1>"; echo "<h2>Today's weather</h2>"; echo "<div class=\"weather\">"; echo "<img src=\"http://www.google.com' . $current[0]->icon['data']\" alt=\"weather\">"; echo "<span class=\"condition\">"; echo "$current[0]->temp_f['data'] ° F,"; echo "$current[0]->condition['data']"; echo "</span>"; echo "</div>"; echo "<h2>Forecast</h2>"; echo "foreach ($forecast_list as $forecast) :"; echo "<div class=\"weather\">"; echo "<img src=\"http://www.google.com' . $forecast->icon['data']\" alt=\"weather\">"; echo "<div>$forecast->day_of_week['data'];</div>"; echo "<span class=\"condition\">";echo "$forecast->low['data'] ?>° F - $forecast->high['data'] ° F,";echo "$forecast->condition['data'] "; echo "</span>"; echo "</div>";?> <?endforeach?> </body></html> and here is the original <?$xml = simplexml_load_file('http://www.google.com/ig/api?weather=jakarta');$information = $xml->xpath("/xml_api_reply/weather/forecast_information");$current = $xml->xpath("/xml_api_reply/weather/current_conditions");$forecast_list = $xml->xpath("/xml_api_reply/weather/forecast_conditions");?><html> <head> <title>Google Weather API</title> </head> <body> <h1><?= print $information[0]->city['data']; ?></h1> <h2>Today's weather</h2> <div class="weather"> <img src="<?= 'http://www.google.com' . $current[0]->icon['data']?>" alt="weather"?> <span class="condition"> <?= $current[0]->temp_f['data'] ?>° F, <?= $current[0]->condition['data'] ?> </span> </div> <h2>Forecast</h2> <? foreach ($forecast_list as $forecast) : ?> <div class="weather"> <img src="<?= 'http://www.google.com' . $forecast->icon['data']?>" alt="weather"?> <div><?= $forecast->day_of_week['data']; ?></div> <span class="condition"> <?= $forecast->low['data'] ?>° F - <?= $forecast->high['data'] ?>° F, <?= $forecast->condition['data'] ?> </span> </div> <? endforeach ?> </body></html> the errors are print ->city['data']; Today's weather weather->temp_f['data'] ° F,->condition['data'] Forecast Notice: Undefined variable: forecast in C:\wamp\www\fiunc\test.php on line 24 foreach (Array as ) : Notice: Undefined variable: forecast in C:\wamp\www\fiunc\test.php on line 26 Notice: Trying to get property of non-object in C:\wamp\www\fiunc\test.php on line 26 weather Notice: Undefined variable: forecast in C:\wamp\www\fiunc\test.php on line 27 Notice: Trying to get property of non-object in C:\wamp\www\fiunc\test.php on line 27 ['data']; Notice: Undefined variable: forecast in C:\wamp\www\fiunc\test.php on line 29 Notice: Trying to get property of non-object in C:\wamp\www\fiunc\test.php on line 29 Notice: Undefined variable: forecast in C:\wamp\www\fiunc\test.php on line 29 Notice: Trying to get property of non-object in C:\wamp\www\fiunc\test.php on line 29 ['data'] ?>° F - ['data'] ° F, Notice: Undefined variable: forecast in C:\wamp\www\fiunc\test.php on line 30 Notice: Trying to get property of non-object in C:\wamp\www\fiunc\test.php on line 30 ['data'] Quote Link to comment Share on other sites More sharing options...
$php_mysql$ Posted October 4, 2010 Author Share Posted October 4, 2010 sorry i meant unable to fix. Quote Link to comment Share on other sites More sharing options...
anups Posted October 4, 2010 Share Posted October 4, 2010 your foreach is in double quote (")... remove it replace this line echo "foreach ($forecast_list as $forecast) :"; by this line foreach ($forecast_list as $forecast) : Quote Link to comment Share on other sites More sharing options...
$php_mysql$ Posted October 4, 2010 Author Share Posted October 4, 2010 did that now it looks like this <html> <head> <title>API</title> </head> <body> <?php $xml = simplexml_load_file('http://www.google.com/ig/api?weather=jakarta'); $information = $xml->xpath("/xml_api_reply/weather/forecast_information"); $current = $xml->xpath("/xml_api_reply/weather/current_conditions"); $forecast_list = $xml->xpath("/xml_api_reply/weather/forecast_conditions"); echo "<h1>print $information[0]->city['data']; </h1>"; echo "<h2>Today's weather</h2>"; echo "<div class=\"weather\">"; echo "<img src=\"http://www.google.com' . $current[0]->icon['data']\" alt=\"weather\">"; echo "<span class=\"condition\">"; echo "$current[0]->temp_f['data'] ° F,"; echo "$current[0]->condition['data']"; echo "</span>"; echo "</div>"; echo "<h2>Forecast</h2>"; foreach ($forecast_list as $forecast) : echo "<div class=\"weather\">"; echo "<img src=\"http://www.google.com' . $forecast->icon['data']\" alt=\"weather\">"; echo "<div>$forecast->day_of_week['data'];</div>"; echo "<span class=\"condition\">"; echo "$forecast->low['data'] ?>° F - $forecast->high['data'] ° F,"; echo "$forecast->condition['data'] "; echo "</span>"; echo "</div>"; endforeach ?> </body> </html> when i run it all i see in the screen is this print ->city['data']; Today's weather weather->temp_f['data'] ° F,->condition['data'] Forecast weather ['data']; ['data'] ?>° F - ['data'] ° F,['data'] weather ['data']; ['data'] ?>° F - ['data'] ° F,['data'] weather ['data']; ['data'] ?>° F - ['data'] ° F,['data'] weather ['data']; ['data'] ?>° F - ['data'] ° F,['data'] Quote Link to comment Share on other sites More sharing options...
anups Posted October 4, 2010 Share Posted October 4, 2010 USE PROPER STRING coNCATANATION <html> <head> <title>API</title> </head> <body> <?php $xml = simplexml_load_file('http://www.google.com/ig/api?weather=jakarta'); $information = $xml->xpath("/xml_api_reply/weather/forecast_information"); $current = $xml->xpath("/xml_api_reply/weather/current_conditions"); $forecast_list = $xml->xpath("/xml_api_reply/weather/forecast_conditions"); echo "<h1>".$information[0]->city['data']."</h1>"; echo "<h2>Today's weather</h2>"; echo "<div class=\"weather\">"; echo "<img src=\"http://www.google.com' . $current[0]->icon['data']\" alt=\"weather\">"; echo "<span class=\"condition\">"; echo $current[0]->temp_f['data']." ° F,"; echo $current[0]->condition['data']; echo "</span>"; echo "</div>"; echo "<h2>Forecast</h2>"; foreach ($forecast_list as $forecast) : echo "<div class=\"weather\">"; echo "<img src=\"http://www.google.com' . $forecast->icon['data']\" alt=\"weather\">"; echo "<div>".$forecast->day_of_week['data']."</div>"; echo "<span class=\"condition\">"; echo $forecast->low['data']."° F - ".$forecast->high['data']."° F,"; echo $forecast->condition['data'] ; echo "</span>"; echo "</div>"; ?> <?php endforeach ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
$php_mysql$ Posted October 4, 2010 Author Share Posted October 4, 2010 thanks for the help :-) just last thing what is wrong here? echo "<img src=\"http://www.google.com'.$current[0]->icon['data'].\" alt=\"weather\">"; i do not get the image but only see it written weather the alt but no sign of image available Quote Link to comment Share on other sites More sharing options...
chintansshah Posted October 4, 2010 Share Posted October 4, 2010 use this string echo "<img src='http://www.google.com".$current[0]->icon['data']."' alt='weather'>"; Quote Link to comment Share on other sites More sharing options...
$php_mysql$ Posted October 4, 2010 Author Share Posted October 4, 2010 thanks soo much :-) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.