Jump to content

covert a value


siclines

Recommended Posts

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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');

}

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

<?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 :D

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.