$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'] Link to comment https://forums.phpfreaks.com/topic/215115-enable-to-fix-the-errors-could-someone-have-a-look/ 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. Link to comment https://forums.phpfreaks.com/topic/215115-enable-to-fix-the-errors-could-someone-have-a-look/#findComment-1118846 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) : Link to comment https://forums.phpfreaks.com/topic/215115-enable-to-fix-the-errors-could-someone-have-a-look/#findComment-1118850 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'] Link to comment https://forums.phpfreaks.com/topic/215115-enable-to-fix-the-errors-could-someone-have-a-look/#findComment-1118852 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> Link to comment https://forums.phpfreaks.com/topic/215115-enable-to-fix-the-errors-could-someone-have-a-look/#findComment-1118862 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 Link to comment https://forums.phpfreaks.com/topic/215115-enable-to-fix-the-errors-could-someone-have-a-look/#findComment-1118868 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'>"; Link to comment https://forums.phpfreaks.com/topic/215115-enable-to-fix-the-errors-could-someone-have-a-look/#findComment-1118885 Share on other sites More sharing options...
$php_mysql$ Posted October 4, 2010 Author Share Posted October 4, 2010 thanks soo much :-) Link to comment https://forums.phpfreaks.com/topic/215115-enable-to-fix-the-errors-could-someone-have-a-look/#findComment-1119070 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.