siclines Posted April 19, 2009 Share Posted April 19, 2009 I have weather data that shows the wind direction in degrees, i want to read the data, and display the letter name for the direction. For example, if the value is 164, I want to display South because the number is between 155 and 200. How would I do that? Quote Link to comment Share on other sites More sharing options...
FaT3oYCG Posted April 19, 2009 Share Posted April 19, 2009 erm that is a bit general so here is a general answer <?php $wind_direction = whatever it is if($wind_direction >= minimum for letter && $wind_direction <= maximum for letter){ echo('North'); }elseif($wind_direction >= minimum for letter && $wind_direction <= maximum for letter){ echo('South'); }elseif($wind_direction >= minimum for letter && $wind_direction <= maximum for letter){ echo('East'); }elseif($wind_direction >= minimum for letter && $wind_direction <= maximum for letter){ echo('West'); } ?> i cant be bothered working the angles out and you might have already done it so whatever, but if you need a more detailed answer i need a more detailed question Quote Link to comment Share on other sites More sharing options...
siclines Posted April 19, 2009 Author Share Posted April 19, 2009 So if $wind_direction is a value from a record in a database, the code would be $result = mysql_query("SELECT wind_direction FROM northbuoy"); $wind_direction = $result if($wind_direction >= minimum for letter && $wind_direction <= maximum for letter){ echo('North'); }elseif($wind_direction >= minimum for letter && $wind_direction <= maximum for letter){ echo('South'); }elseif($wind_direction >= minimum for letter && $wind_direction <= maximum for letter){ echo('East'); }elseif($wind_direction >= minimum for letter && $wind_direction <= maximum for letter){ echo('West'); } Quote Link to comment Share on other sites More sharing options...
FaT3oYCG Posted April 19, 2009 Share Posted April 19, 2009 more like <?php $result = mysql_query("SELECT * FROM northbuoy WHERE ID=whatever the id is"); // selects all records with the id that you give so you should only get one $row = mysql_get_array($result); // gets the firt result, if there are more it will still only use the first $wind_direction = $row['wind_directon']; // where the wind_direction is the value stored in your database if($wind_direction >= minimum for letter && $wind_direction <= maximum for letter){ echo('North'); }elseif($wind_direction >= minimum for letter && $wind_direction <= maximum for letter){ echo('South'); }elseif($wind_direction >= minimum for letter && $wind_direction <= maximum for letter){ echo('East'); }elseif($wind_direction >= minimum for letter && $wind_direction <= maximum for letter){ echo('West'); } ?> if that isnt what you want then please elaborate on what it is that you would like to do and explain the table structure of the specific table in your databse p.s. use code tags Quote Link to comment Share on other sites More sharing options...
siclines Posted April 19, 2009 Author Share Posted April 19, 2009 my database is 6 records in table with 19 fields, I want to display all the 6 rows of data, which i have and work, but the data is stored as a number and I want to display the name (i.e. North) when i return the record. Quote Link to comment Share on other sites More sharing options...
FaT3oYCG Posted April 19, 2009 Share Posted April 19, 2009 ok well the code i posted above is correct replace ID=whatever the id is with the name of the primary key in the table the unique id number and repace the "whatever the id is with the code that selects the id then replace the direction in $wind_direction = $row['directon']; so that it is the name of the feild that holds the number the rest is correct replace the numbers Quote Link to comment Share on other sites More sharing options...
siclines Posted April 19, 2009 Author Share Posted April 19, 2009 the table is always cleared, so the id number is always different, can i make that a function and call the function to convert the value and then display it? Quote Link to comment Share on other sites More sharing options...
ekante Posted April 19, 2009 Share Posted April 19, 2009 <?php while ($row = mysql_fetch_array($result)) { switch ($row[id]){ case ($row[id] >= 120): $row[id] = 'west'; break; } echo $row[id]; } ?> That should do the trick, just write the four of them, im lazy to write them all 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.