delphi123 Posted December 11, 2007 Share Posted December 11, 2007 Ok, I've got a script that's producing rows of a table like this: <?php while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $percent = $row['rating_overall']*10; echo '<tr><td>'.$row['software_name'].'</td><td>'.$percent.'%</td></tr>'; } ?> Now I want the rows to alternate, I was going to create a variable and have two big if statements (ie if variable = 0 then do one which finishes setting it to 1 and then have another loop for the reverse... but then I reckoned one of you guys would have some really clever and intuitive way that I might be able to learn from... ;D Any tips!? Quote Link to comment Share on other sites More sharing options...
JacobYaYa Posted December 11, 2007 Share Posted December 11, 2007 What do you want to alternate? The colors? If so use JavaScript. Quote Link to comment Share on other sites More sharing options...
delphi123 Posted December 11, 2007 Author Share Posted December 11, 2007 yeah, what if folk have js disabled? I figured as the server was already delivering code, then it'd make sense to just deliver an alternating css class for each row. Quote Link to comment Share on other sites More sharing options...
revraz Posted December 11, 2007 Share Posted December 11, 2007 if ($color == $color1){ $color = $color2; }ELSE{ $color = $color1; } Quote Link to comment Share on other sites More sharing options...
delphi123 Posted December 11, 2007 Author Share Posted December 11, 2007 knew there'd be a more elegant way! I'll give it a whirl! Quote Link to comment Share on other sites More sharing options...
revraz Posted December 12, 2007 Share Posted December 12, 2007 It's what I use and it works great. 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.