Jump to content

PHP Arithmetic


natalieG

Recommended Posts

We  want to access  mysql table ad have  row  colors alternate, rows 1,3,5...=white and rows

2,4,6,8..=red.  if we have  a running row counter[$ROWCOUNT] Then we tried:

 

if ($ROWCOUNT %2 ==0){color=red;}else {color=white:}

$ROWCOUNT=$ROWCOUBNT + 1;

but all rows are white

 

Thanks,

 

Jennifer

Link to comment
Share on other sites

Here is what I usually do...

 

$rownum = 0;
while($row = $db->fetch($result)){
//DB stuff here

$tr = $rownum % 2;

echo "<tr class=\"tr".$tr."\">";

//out put information

echo "</tr>";

$x++;

}

 

in the css

.tr0{
background-color:red;
}

.tr1{
background-color:white;
}

 

...something like that, hope it helps

Link to comment
Share on other sites

try

<?php
$ROWCOUBNT = 1;
for ($i = 1; $i < 10; $i ++){
if ($ROWCOUNT %2 ==0){echo 'red';}else {echo 'white';}
$ROWCOUNT=$ROWCOUNT + 1;
echo "<br />\n";
}
?>

it's work

look line $ROWCOUNT=$ROWCOUBNT + 1;

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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