I am trying to display particular images on a web page based on weather conditions. I am able to display individual images using if/elseif statements but when trying to us logic operators to display multiple images for multiple conditions I get now where.
I suspect I am looking in the totally wrong direction.
Here is the code, which includes an explode() function to parse a comma delimited list, as well as a sample of the comma list. The comma list is generated by our in-house weather software and is updated every two minutes or when there is a change in a state.
I work at a small private observatory. We host scopes for hobbiests as well as for some organizations, even have one here for NASA.
The web page I am adding this script to is located at: http://www.nmskies.com/weather.html (there is also a sub domain at
http://hosting.nmskies.com)
I am trying to display images 100 X 640 in either green (open), black (closed for daylight), or red (closed for rain, wind, cloud or fog).
These images will be displayed directly under the weather data at the top of the page and will allow our customers to determine the state of the observatories at a glance.
We have 14 domes and 3 roll of roof that house about 45 scopes in all.
If you need any more information, please let me know.
Thanks for any help.
richardk
start comma list
no sun,no rain,no wind,no clouds,no fog
end of comma list
Code: Select all
<!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="en" lang="en">
<head>
<title></title>
<meta http-equiv="generator" content="CoffeeCup HTML Editor (http://www.coffeecup.com)" />
<meta name="created" content="Sat, 01 Jan 2011 05:31:00 GMT" />
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<style type="text/css">
div.img
{
margin:2px;
margin-left:100px;
height:200px;
width:640px;
float:left;
text-align:center;
}
</style>
</head>
<body>
<div class = "img">
<?php
$filename = "conditions.txt";
$fd = fopen ($filename, "r");
$contents = fread ($fd, "75");
fclose ($fd);
$delimiter = ",";
$split = explode($delimiter, $contents);
if ($split[0] == "sun"){
echo '<img src="images/daylight.jpg?image=.\img\default.jpg&height=200&width=640" />';
}
elseif ($split[1] == "rain"){
echo '<img src="images/rain.jpg?image=.\img\default.jpg&height=200&width=640" />';
}
elseif ($split[2] == "wind"){
echo '<img src="images/wind.jpg?image=.\img\default.jpg&height=200&width=640" />';
}
elseif ($split[3] == "clouds"){
echo '<img src="images/clouds.jpg?image=.\img\default.jpg&height=200&width=640" />';
}
elseif ($split[4] == "fog"){
echo '<img src="images/fog.jpg?image=.\img\default.jpg&height=200&width=640" />';
}
elseif ($split[1] == "rain" && $split[2] == "wind" && $split[3] == "clouds" && $split[4] == "fog"){
echo '<img src="images/rain.jpg?image=.\img\default.jpg&height=200&width=640" />';
echo '<img src="images/wind.jpg?image=.\img\default.jpg&height=200&width=640" />';
echo '<img src="images/clouds.jpg?image=.\img\default.jpg&height=200&width=640" />';
echo '<img src="images/fog.jpg?image=.\img\default.jpg&height=200&width=640" />';
}
else{
echo '<img src="images/open.jpg?image=.\img\default.jpg&height=200&width=640" />';
}
?>
</div>
</body>
</html>