Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If statment Question

Status
Not open for further replies.

james0816

Programmer
Jan 9, 2003
295
US
Is there a way in PHP to program an "OR" conidtion or is it strictly through the use of ELSEIF?

i.e

if ($var1 == 1) OR ($var1 == 2)

something to that effect.
 
use "||", like:

if ($var1 == 1 || $var1 == 2)

 
There is also the switch statement:
Code:
switch ($var1){
   case 1:
   case 2:
      #code here
      break;
   default:
      # default ot more cases as appropriate
}

The use of the operator "OR" is fine, it is the parantheses that made it nor work:
Code:
id ($var1==1 OR $var1==2){
  # etc.
}
 
hmmmm.....guess i may be stuck with just extra lines. is this pretty much the way to code this:

if ($lj != 0 && $RR == 1)
{
echo"<tr height=15 bgcolor=#ffffdd>";
}
elseif ($lj == 2 && $RR < 6)
{
echo"<tr height=15 bgcolor=#ffffdd>";
}
elseif ($lj == 3 && $RR < 11)
{
echo"<tr height=15 bgcolor=#ffffdd>";
}

else
{
echo"<tr height=15 bgcolor=#eeeeee>";
}
 
actually the first line should be $lj == 1

sry
 
Code:
if (($lj==1 && $RR == 1)
    OR ($lj==2 && $RR<6)
    OR ($lj==3 && $RR<11)){
    echo '<tr height="15" bgcolor="#ffffdd">';
} else {
        echo '<tr height="15" bgcolor="#ffffdd">';
}

Some things I noticed:
1. for validation purposes one should double quote tag attributes.
2. a class attribute is IMHO better than using explicit setting of the background color. With CSS you can restyle the output without having to touch the code.
 
definately much smoother.

i did try with the double quotes...didn't like it...gave me an error so i removed them and it worked. I am using single quotes now.

for the CSS I would define the CSS style and then replace the bgcolor= with style=?
 
Code:
<tr class="myclass">...
A CSS style definition - best in an external css file linked with a <link> tag:
Code:
tr.myclass {
   background-color: #ffffdd;
   height: 15px;
   font-size: 11px;
}

Unfortunately if you were to work in a place that required HTML, XHTML validation, you would not have a choice as to like or dislike double quotes. It is also a good practice and shows ones professionalism to keep up web standards recommended by the W3C.
 
true...i didnt mean that i didnt like the double quotes. what i meant was that the webserver or whatever is governing that didn't like them as it gave me an error when i reloaded the page.
 
DRJ478 said:
Unfortunately if you were to work in a place that required HTML, XHTML validation, you would not have a choice as to like or dislike double quotes. It is also a good practice and shows ones professionalism to keep up web standards recommended by the W3C.[/code]
Incidentally, standards say that attributes must be quoted, not double quoted. Single or double quotes will pass the validation with any doctype.
 
i haven't tested but the if above seems to say
Code:
if ($lj <=3 && $lj>0 && $RR< 11)
    echo '<tr height="15" bgcolor="#ffffdd">';
else
     echo '<tr height="15" bgcolor="#eeeeee">';

Binary Intelligence, true or false?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top