tsh9 Posted August 15, 2010 Share Posted August 15, 2010 Hello! I don't have a lot of experience wih PHP. I'm trying to make a page with two drop down list. The first one is a list of countries generated from an array. When the user selects a country a second drop down list is generated (dynamically) with a list cities from that country using an url: http://www.webservicex.net/globalweather.asmx/GetCitiesByCountry?CountryName=NP (where NP is the country name) and then get the weather info for the city from the selected country using: http://www.webservicex.net/globalweather.asmx/GetWeather?CityName=NV&CountryName=NP (Where NV is for the City name and NP the country name). I have a few problems 1. I would like to have the selected country/city stay the same even after submitting the request. 2. Have the weather information display after submitting the request. I have also included the files in a zip file. Any help would be greatly appreciated ! Thank you. <?php require("lib/util.lib.php"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>La météo de la planète</title> <link rel="stylesheet" href="css/jqtransform.css" type="text/css" media="all" /> <link rel="stylesheet" href="css/style.css" type="text/css" media="all" /> <script src="http://www.google.com/jsapi" type="text/javascript"></script> <script type="text/javascript"> google.load("jquery", "1.3.2"); </script> <script type="text/javascript" src="js/jquery.jqtransform.js"></script> <script type="text/javascript" src="js/jquery.form.js"></script> <script type="text/javascript" src="js/websitechange.js"></script> </head> <body> <div id="page-wrap"> <h1>Weather around the world</h1> <form action="index.php" method="get" id="change-form"> <div class="rowElemSelect"> <label for="listCountry">Choose a country:</label> <select name="country"> <?php listePays(); ?> </select> <> <div class="rowElem"> <label> </label> <input type="submit" name="btnSubmitCountry" value="Submit" /> <> <div class="rowElemSelect"> <?php if(isset($_GET["btnSubmitCountry"]) && $_GET["country"] !=="") { $url = "http://www.webservicex.net/globalweather.asmx/GetCitiesByCountry?CountryName=".$_GET["country"]; $page = file_get_contents($url); $pattern = '/<City>(.*)<\/City>/'; preg_match_all($pattern, $page, $matches); echo '<label for="listCity">Choose a city:</label>'; echo '<select name="city">'; for($i=0; $i< count($matches[1]); $i++) { echo '<option value ="'.$matches[1][$i].'">'.$matches[1][$i].'</option>'; } echo '</select>'; echo '<div class="rowElem">'; echo '<label> </label>'; echo '<input type="submit" name="btnSubmitCity" value="Submit" />'; echo '<>'; } ?> <div class="rowElemSelect"> <?php if(isset($_GET["btnSubmitCity"]) && $_GET["country"] !=="" && $_GET["city"] !=="") { $url = "http://www.webservicex.net/globalweather.asmx/GetWeather?CityName=".$_GET['city']."NV&CountryName=".$_GET['country']; $page = file_get_contents($url); print_r($page); } ?> </form> <!--End page-wrap--> </body> </html> [attachment deleted by admin] 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.