rcouser Posted September 3, 2008 Share Posted September 3, 2008 Hello I am trying to created alternative coloured rows for my database results, I had a go with the code below but the result only display with the one style. The two styles are range1 and range2. Could someone please help and see were I've went wrong. Thanks <?php // initialize cell counter outside loop $row_colour = 1; $rowStyle = ($row_colour % 2 == 1) ? 'range1' : 'range2'; do { ?> <div class="<?php echo "$rowStyle" ?>"> <div class="rangedetails"> <h5><?php echo $ranges['range_title']; ?></h5> <p><?php echo $ranges['range_description']; ?></p> </div> <div class="editbutton"> <a href="update_range.php?range_id=<?php echo $ranges['range_id']; ?>">Edit</a> </div> <div class="deletebutton"> <a href="delete_range.php?range_id=<?php echo $ranges['range_id']; ?>">Delete</a> </div> </div> <?php $ranges = $result->fetch_assoc(); $row_colour++; } while ($ranges); ?> Link to comment https://forums.phpfreaks.com/topic/122566-alternative-coloured-rows/ Share on other sites More sharing options...
The Little Guy Posted September 3, 2008 Share Posted September 3, 2008 Example: http://phpsnips.com/snippet.php?id=52 Link to comment https://forums.phpfreaks.com/topic/122566-alternative-coloured-rows/#findComment-632845 Share on other sites More sharing options...
genericnumber1 Posted September 3, 2008 Share Posted September 3, 2008 <?php // initialize cell counter outside loop $row_colour = 1; do { $rowStyle = ($row_colour % 2 == 1) ? 'range1' : 'range2';?> <div class="<?php echo "$rowStyle" ?>"> <div class="rangedetails"> <h5><?php echo $ranges['range_title']; ?></h5> <p><?php echo $ranges['range_description']; ?></p> </div> <div class="editbutton"> <a href="update_range.php?range_id=<?php echo $ranges['range_id']; ?>">Edit</a> </div> <div class="deletebutton"> <a href="delete_range.php?range_id=<?php echo $ranges['range_id']; ?>">Delete</a> </div> </div> <?php $ranges = $result->fetch_assoc(); $row_colour++; } while ($ranges); ?> you needed to move the $rowStyle = line down one. evil do{}while() loops..... Link to comment https://forums.phpfreaks.com/topic/122566-alternative-coloured-rows/#findComment-632848 Share on other sites More sharing options...
rcouser Posted September 3, 2008 Author Share Posted September 3, 2008 Thanks for the help, I thought it was something simple. Why are do{}while() loops evil Link to comment https://forums.phpfreaks.com/topic/122566-alternative-coloured-rows/#findComment-632864 Share on other sites More sharing options...
discomatt Posted September 3, 2008 Share Posted September 3, 2008 They're 'evil' cause they're the only control structure with the arguments at the bottom - forces a slightly different approach. There's nothing wrong with using them. Link to comment https://forums.phpfreaks.com/topic/122566-alternative-coloured-rows/#findComment-632873 Share on other sites More sharing options...
genericnumber1 Posted September 3, 2008 Share Posted September 3, 2008 they're a little more difficult to read that's the only reason I said they're evil. Link to comment https://forums.phpfreaks.com/topic/122566-alternative-coloured-rows/#findComment-632875 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.