Kimaos Posted March 27, 2012 Share Posted March 27, 2012 Hello, I need help for displaying weather on my blog, I'm not good in php coding I have a yahoo php script that displays weather forecast for only one city I would like to add a dropdownlist to display weather depending on the selected city the problem is that I do not know how to replace « $zip = "FRXX0055"; » by dropdownlist selected value I do not know if it is feasible, because city selection must communicate with « weather.class.php » and get weather without reloading the page initial code : <?php include('weather.class.php'); $zip = "FRXX0055"; define('DEFAULT_UNITS', "c"); define('IMAGES', 'icons/sm/'); if($zip != '') { if (isset($_GET['units'])) {$s_unit_of_measure = strtolower($_GET['units']);} else {$s_unit_of_measure = DEFAULT_UNITS;} $weather = new Weather(); $weather = $weather->getWeather($zip, $s_unit_of_measure); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Test List Php</title> </head> <body> <table> <tr> <td colspan="3">Lyon</td> </tr> <tr> <td><span><?php echo strtoupper($weather['forecast'][0]['when']) ?></span><br /> <span>Max: <strong><?php echo $weather['forecast'][0]['high'] ?></strong></span><br /> <span>Min: <strong><?php echo $weather['forecast'][0]['low'] ?></strong></span><br /> <img src="<?php echo $weather['forecast'][0]['image'] ?>" alt="Weather Widget" /></td> <td><span><?php echo strtoupper($weather['forecast'][1]['when']) ?></span><br /> <span>Max: <strong><?php echo $weather['forecast'][1]['high'] ?></strong></span><br /> <span>Min: <strong><?php echo $weather['forecast'][1]['low'] ?></strong></span><br /> <img src="<?php echo $weather['forecast'][1]['image'] ?>" alt="Weather Widget" /></td> <td><span><?php echo strtoupper($weather['forecast'][2]['when']) ?></span><br /> <span>Max: <strong><?php echo $weather['forecast'][2]['high'] ?></strong></span><br /> <span>Min: <strong><?php echo $weather['forecast'][2]['low'] ?></strong></span><br /> <img src="<?php echo $weather['forecast'][2]['image'] ?>" alt="Weather Widget" /></td> </tr> </table> </body> </html> new code : <?php include('weather.class.php'); $zip = "FRXX0055"; define('DEFAULT_UNITS', "c"); define('IMAGES', 'icons/sm/'); if($zip != '') { if (isset($_GET['units'])) {$s_unit_of_measure = strtolower($_GET['units']);} else {$s_unit_of_measure = DEFAULT_UNITS;} $weather = new Weather(); $weather = $weather->getWeather($zip, $s_unit_of_measure); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Test List Php</title> </head> <body> <table> <tr> <td colspan="3"> <select id ="city" onchange="ShowItem()"> <option value="FRXX0055">Lyon</option> <option selected value="FRXX0076">Paris</option> <option value="FRXX0059">Marseille</option> <option value="FRXX0095">Strasbourg</option> </select> </td> </tr> <tr> <td><span><?php echo strtoupper($weather['forecast'][0]['when']) ?></span><br /> <span>Max: <strong><?php echo $weather['forecast'][0]['high'] ?></strong></span><br /> <span>Min: <strong><?php echo $weather['forecast'][0]['low'] ?></strong></span><br /> <img src="<?php echo $weather['forecast'][0]['image'] ?>" alt="Weather Widget" /></td> <td><span><?php echo strtoupper($weather['forecast'][1]['when']) ?></span><br /> <span>Max: <strong><?php echo $weather['forecast'][1]['high'] ?></strong></span><br /> <span>Min: <strong><?php echo $weather['forecast'][1]['low'] ?></strong></span><br /> <img src="<?php echo $weather['forecast'][1]['image'] ?>" alt="Weather Widget" /></td> <td><span><?php echo strtoupper($weather['forecast'][2]['when']) ?></span><br /> <span>Max: <strong><?php echo $weather['forecast'][2]['high'] ?></strong></span><br /> <span>Min: <strong><?php echo $weather['forecast'][2]['low'] ?></strong></span><br /> <img src="<?php echo $weather['forecast'][2]['image'] ?>" alt="Weather Widget" /></td> </tr> </table> </body> </html> Thank you for help, Link to comment https://forums.phpfreaks.com/topic/259833-help-to-add-dropdownlist-to-weather-script/ Share on other sites More sharing options...
cpd Posted March 27, 2012 Share Posted March 27, 2012 I do not know if it is feasible, because city selection must communicate with « weather.class.php » and get weather without You can't use just PHP to update information on a page. You need to use JavaScript, more specifically XMLHttpRequest; this is all summed up with the term AJAX. Link to comment https://forums.phpfreaks.com/topic/259833-help-to-add-dropdownlist-to-weather-script/#findComment-1331708 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.