PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
kingdbag
Forum Newbie
Posts: 22 Joined: Wed Jul 12, 2006 6:22 pm
Post
by kingdbag » Wed Jul 12, 2006 6:42 pm
I need some help... thanks!
$freqa= 24.9;
if($freqa != 24.9 || $freqa != 36.4)
{
echo ("<h1>Not running at 24.9 or 36.4 RUNNING AT $freqa</h1>");
}
else
{
echo ("<h1>Is running normal</h1>");
}
thing is no matter what i set freqa to it still says its not running at 24.9 or 36.4 even though it is.
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Wed Jul 12, 2006 6:51 pm
First, please wrap PHP code in the appropriate bbCode tags.
Next, here is what it should look like, with comments to answer your question.
Code: Select all
<?php
// Give $freqa a value
$freqa= 24.9;
if ( $freqa != 24.9 )
{
if ( $freqa != 36.4 )
{
// If we are here then $freqa either does not equal 24.9 OR it does not equal 36.4)
echo ("<h1>Not running at 24.9 or 36.4 RUNNING AT $freqa</h1>");
}
else
{
// If we are here then $freqa does not equal 24.9 but it DOES equal 36.4)
echo ("<h1>Running at 36.4</h1>");
}
}
else
{
// We are 24.9
echo ("<h1>Is running normal</h1>");
}
?>
kingdbag
Forum Newbie
Posts: 22 Joined: Wed Jul 12, 2006 6:22 pm
Post
by kingdbag » Wed Jul 12, 2006 6:54 pm
Sorry about that, there is no way in php to OR both statements into one line?
Benjamin
Site Administrator
Posts: 6935 Joined: Sun May 19, 2002 10:24 pm
Post
by Benjamin » Wed Jul 12, 2006 7:06 pm
Untested...
Code: Select all
$freqa= '24.9';
switch ($freqa) {
case '24.9':
case '36.4':
echo '<h1>Is Running Normal</h1>';
break;
default:
echo ("<h1>Not running at 24.9 or 36.4 RUNNING AT $freqa</h1>");
}
In your code..
Code: Select all
if($freqa != 24.9 || $freqa != 36.4)
This will
always return true, as $freqa is not going to be equal to one of the two.
dull1554
Forum Regular
Posts: 680 Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W
Post
by dull1554 » Wed Jul 12, 2006 7:11 pm
you can also do this:
Code: Select all
$freqa= 24.9;
if(($freqa != 24.9) || ($freqa != 36.4)) //this should work
{
echo "<h1>Not running at 24.9 or 36.4 RUNNING AT $freqa</h1>";
}
else
{
echo "<h1>Is running normal</h1>";
}
Benjamin
Site Administrator
Posts: 6935 Joined: Sun May 19, 2002 10:24 pm
Post
by Benjamin » Wed Jul 12, 2006 7:12 pm
dull1554 wrote: you can also do this:
You might want to take another look at that.
dull1554
Forum Regular
Posts: 680 Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W
Post
by dull1554 » Wed Jul 12, 2006 7:26 pm
astions wrote: dull1554 wrote: you can also do this:
You might want to take another look at that.
ok that dosnt work, this does
Code: Select all
<?php
$freqa= 24.7;
if(($freqa == 24.9) || ($freqa == 36.4)) //this should work
{
echo "<h1>Is running normal</h1>";
}
else
{
echo "<h1>Not running at 24.9 or 36.4 RUNNING AT $freqa</h1>";
}
?>
kingdbag
Forum Newbie
Posts: 22 Joined: Wed Jul 12, 2006 6:22 pm
Post
by kingdbag » Thu Jul 13, 2006 12:47 am
thanks guys... i really appreciate the responese!