Jump to content


Photo

Help with IF statements and the || and && conditions


  • Please log in to reply
2 replies to this topic

#1 HookedOnWeb

HookedOnWeb
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 15 March 2006 - 10:54 PM

I am trying to echo a when a range of number are between a starting and stopping number. For example:

When I is >= 12 and <=18 echo I

I am having trouble writing the conditional statement. Checking for one number is easy but when I try to check if the number is between two numbers, it cannot get it to work.

I am try:

$start = 12;
$end = 18;

for ($i=1; $i >= $start && $today <= $end; $1++) {
echo $i . "<br>";
}

What I want to happen is to print out are the numbers 12 - 18 down the screen.

I am using the FOR loop to test the condition. What I am really trying to do is add a IF condition to the code I have already written, for example:

if ($today >= $start && $today <= $end) {
echo "The range is between " . $i . "<br>";
}

This echo is just there for the example I am actually printing out something else, this way it was easier to read.

I know this is basic but I am learning.

#2 saiko

saiko
  • Members
  • PipPipPip
  • Advanced Member
  • 37 posts

Posted 15 March 2006 - 11:11 PM

&& equals and

|| equals or



$start = 12;
$end = 18;

if(($today >= $start) && ($today <= $end)) {
echo "The range is between " . $i . "<br>";
}

hope it helps :D

#3 HookedOnWeb

HookedOnWeb
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 16 March 2006 - 12:54 AM

Yes that helped and the code is now working the way I wanted to, thanks!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users