1

I am wondering how to change this :

This code is using a table and I instead trying to use a div, but I wanna define the div the same way it's done with enter <td>. In <td class= '".$class." thum'> here Like enter <div class='".$class." thumb'> here

enter <td ' class='".$class." thumb'><div align='center'><a href='show-".$row['id'].".php'><img src='".$row['image']."' width='80' height='60' /></a></div></td> here

I am trying to change color on each iteration of loop. That's what $class is there.

I don't think this is clear at all. It's hard to explain it

Thanks in advance

1 Answer 1

2

You could define a new value within each loop prior to echoing the output. For instance, if you wanted "zebra stripes," you could check if the current iteration is even or odd:

for ( $i = 0; $i < count( $items ); $i++ ) {
  $style = ( $i % 2 == 0 ) ? $styleA : $styleB ;
  echo "<td class='{$style} thumb'>...</td>";
}

Sample Output: http://codepad.org/8cYyiBBH

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, it doesn't work when I use a div. echo "<div class='{$style} thumb'>...</div>"; It works for TD though
@Rocks It will work for any element. It will work for div as well, unless your class is defined with the expectation that it will be used with a td, like td.foo { color: red }. That, for obvious reasons, wouldn't work when the class is added to a div.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.