if-else with mod and CSS

What is incorrect?:

 if ($i%2==1)
  {
     echo '<tr class=\"other\">';
  }
LVL 7
weikelbobAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sajuksCommented:
What error are u getting ?

 if($i%2): $color = "#FFFFFF"; else: $color = "#CCCCCC"; endif;

is assume this is related to the alternate table row color ?
then use this
$s = "<table>\r\n";
for($x=0;$x<count($array);$x++){
    if($x/2 == round($x/2)){
        $c = "class=\"normal\"";
    }else{
        $c = "class=\"other\"";
    }
    $s .= "<tr>";
    $s .= "<td $c>".$array[$x]."</td>";
    $s .= "</tr>\r\n";
}
$s .= "</table>\r\n";
echo $s;
$s .= "</table>\r\n";
echo $s;
or
or Heres a simple ex:http://www.phpfreaks.com/tutorials/5/0.php
sajuksCommented:
//try this
<?php
echo "<table border=0 cellspacing=0 cellpadding=0>";
$num=20;
for($i=0;$i<$num;$i++){

  if($i % 2 ==0)
  {
    $bgcolor='#f3f3f3';
  }
  else
  {
    $bgcolor='#e3e3e3';
  }

  // echo the table content with $bgcolor
  echo "<tr bgcolor=$bgcolor><td> This is line number $i </td></tr>";

// close loop
}

// close table
echo "</table>";
?>
weikelbobAuthor Commented:
That's almost what I have:

for ($i=0; $i<count($name); $i++)
{
  echo if ($i % 2==1)
  {
     echo '<tr class=\"other\">';
  }
  else
  {  
     echo '<tr class=\"normal\">';
  }
...echo stuff
}
OWASP: Forgery and Phishing

Learn the techniques to avoid forgery and phishing attacks and the types of attacks an application or network may face.

weikelbobAuthor Commented:
echo if should be if. Nothing happens, no error.
sajuksCommented:
why an echo for the if stmnt ??
"echo if ($i % 2==1)" shouldnt that be if ($i % 2==1)
try this

if ($i % 2==1)
{
    $myclass='other';
  }
  else
  {
    $myclass='normal';
  }
echo "<tr class=$myclass><td> .....";

 
weikelbobAuthor Commented:
Not getting it, here's all related code:

tr.normal
{
   background-color:#FFFFFF;
}

tr.other
{
background-color:#000000;
}
...
for ($i=0; $i<count($name); $i++)
{
if ($i % 2==1)
{
$myclass='other';
}
else
{
$myclass='normal';
}
echo "<tr class=$myclass>";

echo ...
}
sajuksCommented:
Change
if ($i % 2==1)
to
if ($i % 2==0)
weikelbobAuthor Commented:
Nope. I think I'm overlooking something.
sajuksCommented:
Check the ex at :http://www.phpfreaks.com/tutorials/5/0.php
Are u getting any output ordoes teh screen show blank>
weikelbobAuthor Commented:
IE gives me all green, firefox gives me nothing.

sajuksCommented:
// save this as an php file .do u see alternate colors ?
<style>
tr.normal
{
   background-color:#FFFFFF;
}

tr.other
{
background-color:#eeefff;
}
</style>

<?php
echo "<table border=0 cellspacing=0 cellpadding=0>";
$num=20;
for($i=0;$i<$num;$i++){

  if($i % 2 ==0)
  {
    $myclass='normal';
  }
  else
  {
    $myclass='other';
  }

  // echo the table content with $bgcolor
  echo "<tr class=$myclass><td> This is line number $i </td></tr>";

// close loop
}

// close table
echo "</table>";
?>

Can u post the o/p of ur page (html code thats generated ) or provide a link to the page ?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
weikelbobAuthor Commented:
finally got it sajuks. I copied and pasted exactly from that .php file you sent me.

Thank you for your help

Bob
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.