Jump to content

covert a value


siclines

Recommended Posts

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
https://forums.phpfreaks.com/topic/154783-covert-a-value/#findComment-813959
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
https://forums.phpfreaks.com/topic/154783-covert-a-value/#findComment-813967
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
https://forums.phpfreaks.com/topic/154783-covert-a-value/#findComment-813971
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
https://forums.phpfreaks.com/topic/154783-covert-a-value/#findComment-814000
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
https://forums.phpfreaks.com/topic/154783-covert-a-value/#findComment-814021
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.