snup Posted September 29, 2014 Share Posted September 29, 2014 Okay, so I am trying to display players usernames and kills and deaths from my highscores page and I have different div classes set for each block This is my code: <div id="table"> <div class="tr ttl"> <div class="col st1">Rank</div> <div class="col st2">Username</div> <div class="col st3">Rating</div> <div class="col st4">Deaths</div> <div class="col st5">Kills</div> </div> <?php if($_GET['skill'] == 0) { $skill = $_GET['skill']; $page = ($_GET['page']-1); $limit = RESULTS_PER_PAGE*$page.', '.RESULTS_PER_PAGE; $limitt = RESULTS_PER_PAGE*$page; $query = "SELECT * FROM hs ORDER BY `elo` DESC LIMIT ".$limit.""; $result = mysql_query($query); $counter = 1; while ($fetch = mysql_fetch_assoc($result)) { echo '<div class="tr normal ftr rd1"> <div class="col st1">'.($counter+$limitt).'</div> <div class="col st2"><a href="?user='.$fetch['username'].'">'.$fetch['username'].'</a></div> <div class="col st3">'.number_format($fetch['kills']).'</div> <div class="col st4">'.number_format($fetch['deaths']).'</div> <div class="col st5">'.$fetch['elo'].'</div> </div> '; $counter++; } } ?> See where it says echo '<div class="tr normal ftr rd1"> I'd want it to print out like this: (tr normal ftr rd1) for the first one, (tr normal ftr rd2) for second one and (tr normal ftr rd3) for the 3rd one. Then (tr normal) and (tr odd normal) for the rest Can anyone help me out here? Quote Link to comment https://forums.phpfreaks.com/topic/291347-help-with-displaying-something/ Share on other sites More sharing options...
Solution Ch0cu3r Posted September 29, 2014 Solution Share Posted September 29, 2014 (edited) So the first three rows will have the the rdX class applied. Then the remaining rows have the odd class is applied alternatively? Using your $counter variable we can alternate the classes at the start of the loop, example (untested code) $counter = 1; while ($fetch = mysql_fetch_assoc($result)) { // common css classes for every row $class = "tr normal"; // if counter is less than or equal to 3 apply the ftr and rdX css class if($counter <= 3) { $class .= " ftr rd$counter"; } // otherwise apply the odd css class for every alternative row else if($counter % 2 != 0) { $class .= " odd"; } // apply the css class definitions echo '<div class="'.$class.'"> .... </div>'; $counter++; } Edited September 29, 2014 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/291347-help-with-displaying-something/#findComment-1492371 Share on other sites More sharing options...
snup Posted September 29, 2014 Author Share Posted September 29, 2014 So the first three rows will have the the rdX class applied. Then the remaining rows have the odd class is applied alternatively? Using your $counter variable we can alternate the classes at the start of the loop, example (untested code) $counter = 1; while ($fetch = mysql_fetch_assoc($result)) { // common css classes for every row $class = "tr normal"; // if counter is less than or equal to 3 apply the ftr and rdX css class if($counter <= 3) { $class .= " ftr rd$counter"; } // otherwise apply the odd css class for every alternative row else if($counter % 2 != 0) { $class .= " odd"; } // apply the css class definitions echo '<div class="'.$class.'"> .... </div>'; $counter++; } First thanks for the reply and help The first three I am trying to have: 1) <div class="tr normal ftr rd1"> 2) <div class="tr normal ftr rd2"> 3)<div class="tr normal ftr rd1"> The first three are in bold to show top 3 players but are slightly different in color tone so show difference then the rest after that are even and odd to show different colors like you have posted Quote Link to comment https://forums.phpfreaks.com/topic/291347-help-with-displaying-something/#findComment-1492374 Share on other sites More sharing options...
Ch0cu3r Posted September 29, 2014 Share Posted September 29, 2014 Wait... Before you said the top three rows will be rd1 for first row, rd2 for second row and rd3 for the third. Now you are saying the top three rows alternate between rd1 and rd2? Which is it? Quote Link to comment https://forums.phpfreaks.com/topic/291347-help-with-displaying-something/#findComment-1492377 Share on other sites More sharing options...
snup Posted September 29, 2014 Author Share Posted September 29, 2014 Wait... Before you said the top three rows will be rd1 for first row, rd2 for second row and rd3 for the third. Now you are saying the top three rows alternate between rd1 and rd2? Which is it? my bad i didn't notice i wrote that already rd1 is bold yellow rd2 is bold lighter yellow rd3 is bold yellow - the same as rd1 Quote Link to comment https://forums.phpfreaks.com/topic/291347-help-with-displaying-something/#findComment-1492381 Share on other sites More sharing options...
Ch0cu3r Posted September 29, 2014 Share Posted September 29, 2014 And that is what my code does. Example output from my code <div class="tr normal ftr rd1">...</div> <div class="tr normal ftr rd2">...</div> <div class="tr normal ftr rd3">...</div> <div class="tr normal">...</div> <div class="tr normal odd">...</div> <div class="tr normal">...</div> <div class="tr normal odd">...</div> ...etc Quote Link to comment https://forums.phpfreaks.com/topic/291347-help-with-displaying-something/#findComment-1492384 Share on other sites More sharing options...
snup Posted September 29, 2014 Author Share Posted September 29, 2014 And that is what my code does. Example output from my code <div class="tr normal ftr rd1">...</div> <div class="tr normal ftr rd2">...</div> <div class="tr normal ftr rd3">...</div> <div class="tr normal">...</div> <div class="tr normal odd">...</div> <div class="tr normal">...</div> <div class="tr normal odd">...</div> ...etc Sorry I was reading it all on my phone and was a bit confused. But got it fixed now! You're the man thanks so much! Quote Link to comment https://forums.phpfreaks.com/topic/291347-help-with-displaying-something/#findComment-1492387 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.