Jump to content

Help with displaying something


snup
Go to solution Solved by Ch0cu3r,

Recommended Posts

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?

 

Link to comment
Share on other sites

  • Solution

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 by Ch0cu3r
Link to comment
Share on other sites

 

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

 

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.