adilmarwat Posted February 19, 2010 Share Posted February 19, 2010 I want to create a dynamic table in php that it 1st row color is blue and 2nd row color is white and so on. How it is possible. Adil Link to comment Share on other sites More sharing options...
yoursanjay Posted February 19, 2010 Share Posted February 19, 2010 make 2 css for blue & white respectively.in the for or while loop whatever u use, find the row serial no is odd or even.make a if clause in the class section in the td like <td class = "<?php if (serial no is odd, echo blue class... else echo white clsss.);?>"> your content</td>I think you can implement the concept with the Codes. It's very easy dude.. Link to comment Share on other sites More sharing options...
justsomeguy Posted February 19, 2010 Share Posted February 19, 2010 Most of the time people use a counter and the mod operator to do that. If you only have 2 possible options, you can also just use a boolean flag: $odd = true;for ($i = 0; $i < 5; $i++){ if ($odd) echo '<div class="class1">'; else echo '<div class="class2">'; echo 'xxx</div>'; $odd = !$odd;} Each time through that loop $odd will be toggled, so it will alternate between printing divs which have class1 or class2. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.