Jump to content

Help to add dropdownlist to weather script


Kimaos

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.