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. Quote Link to comment 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++; } Quote Link to comment 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 } } Quote Link to comment 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... Quote Link to comment 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++; } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.