Jump to content

Alternative coloured rows


rcouser

Recommended Posts

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

<?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.....

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.