son.of.the.morning Posted December 5, 2011 Share Posted December 5, 2011 alright guys, i am having a little trouble trying to get atl styles within a while loop and wondered if anyone could help? <?php $rowNum = "0"; while($record_rows = mysql_fetch_array($records_returned)){ if(++$rowNum % 2 == 1 ) { ?> <div class="Record-style1"> </div> <?php } else {?> <div class="Record-style2"> </div> <?php }} mysql_close();?> Quote Link to comment https://forums.phpfreaks.com/topic/252498-while-loop-with-2-styles/ Share on other sites More sharing options...
floridaflatlander Posted December 5, 2011 Share Posted December 5, 2011 Have you viewed your source code? Somethings wrong with your css or with the html that your php is echoing. Also it helps to have something in a div to see your style if your divs don't have height. Quote Link to comment https://forums.phpfreaks.com/topic/252498-while-loop-with-2-styles/#findComment-1294537 Share on other sites More sharing options...
AyKay47 Posted December 5, 2011 Share Posted December 5, 2011 it looks like you are checking if the incremented number is an even number, if that is the case.. the modulus operator will return 0 since their is not remainder. if(++$rowNum % 2 == 0 ) { //even number Quote Link to comment https://forums.phpfreaks.com/topic/252498-while-loop-with-2-styles/#findComment-1294550 Share on other sites More sharing options...
Pikachu2000 Posted December 5, 2011 Share Posted December 5, 2011 $rowNum = "0"; while($record_rows = mysql_fetch_array($records_returned)) { $style = $rowNum % 2 === 0 ? 'Record-style1' : 'Record-style2'; echo "<div class=\"{$style}\">$data_and_stuff<div>"; $rowNum++; } Quote Link to comment https://forums.phpfreaks.com/topic/252498-while-loop-with-2-styles/#findComment-1294724 Share on other sites More sharing options...
son.of.the.morning Posted December 6, 2011 Author Share Posted December 6, 2011 Got his working guys! Quote Link to comment https://forums.phpfreaks.com/topic/252498-while-loop-with-2-styles/#findComment-1294837 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.