daveoffy Posted May 19, 2009 Share Posted May 19, 2009 I want to make a list of things such as on https://www.scriptlance.com/programmers/projects.shtml. I know how to pull data from database. But how do I make every other one a different colour. Such as Gray, Light Gray, Gray, Light Gray... etc. Link to comment https://forums.phpfreaks.com/topic/158673-solved-php-list-different-colors/ Share on other sites More sharing options...
Masna Posted May 19, 2009 Share Posted May 19, 2009 $get_rows = mysql_query("SELECT * FROM `list_of_things`"); $i = 0; while($row = mysql_fetch_assoc($get_rows)){ if($i % 2 == 0){ $bg_color = 'light-grey'; } else { $bg_color = 'grey'; } //echo information you want displayed $i++; } Link to comment https://forums.phpfreaks.com/topic/158673-solved-php-list-different-colors/#findComment-836860 Share on other sites More sharing options...
daveoffy Posted May 19, 2009 Author Share Posted May 19, 2009 Will this also work? $Color = #FFFFFF; while (1) { echo '<div style="background-color: '.$Color.'">Hello</div>'; if ($Color == #FFFFFF) { $Color = #555555 }elseif ($Color == #555555) { $Color = #FFFFFF } } Link to comment https://forums.phpfreaks.com/topic/158673-solved-php-list-different-colors/#findComment-836897 Share on other sites More sharing options...
Masna Posted May 19, 2009 Share Posted May 19, 2009 Yes, it will. But don't forget to quote the actual hex colors. Although, you've created an infinite loop there... Link to comment https://forums.phpfreaks.com/topic/158673-solved-php-list-different-colors/#findComment-836903 Share on other sites More sharing options...
jlhaslip Posted May 19, 2009 Share Posted May 19, 2009 <?php $c="#cccccc"; while ($i <10) { echo '<p style="background-color:' . (($c == "#cccccc") ? $c = "#eeeeee" : $c = "#cccccc") . ';">Paragraph</p>'; $i++; } ?> Link to comment https://forums.phpfreaks.com/topic/158673-solved-php-list-different-colors/#findComment-836947 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.