Jump to content

Recommended Posts

Hi PHP Masters

 

I'm trying to get a scoreboard set up. I seem to have got the scoreboard working and the registering of scores setup. BUT I want some automated css styles applied to all rows in the table depending on what score they achieve, so it would be a bronze silver and gold awards.

 

so if they did more than 100 press-ups they receive a gold colour  above 50 and below 99 would be a silver colour  and so on.

 

I hope everyone understands this.

 

here is a link to the existing board

 

http://www.igloo-design.org/08/view_users.php

Link to comment
https://forums.phpfreaks.com/topic/154869-help-with-school-scoreboard/
Share on other sites

function changeCssScore($score=0) {
    if ($score > 100) {
           $return = "gold";
    }elseif ($score > 80) {
           $return = "silver";
    }else {
            $return = "bronze";
    }
  
    return $return;
}

$score = 79;
echo '<tr class="' . changeCssScore($score) .'"><td>Score was ' . $score . '</td></tr>';

Inline css is suggested against doing not recommended. Mainly because in order for you to modify the style you manually have to change the page.

 

Whereas with CSS being in a file, you can change the values of that file and have easy portability to a new theme, new color scheme etc. It is better to keep it in an external CSS file due to that.

 

You want to make it easier for you to modify your script's scheme later on, not harder :)

Hi Im still having problems

 

this is the code I am using to display the rows with alternate styling

 

$bg = '#eeeeee'; // Set the background color.
while ($row = mysql_fetch_array($result)) {
$bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee'); // Switch the background color.

echo '<tr bgcolor="' . $bg . '">
	<td align="left">' . $row['player'] . '</td>
	<td align="left">' . $row['school'] . '</td>
	<td align="left">' . $row['score'] . '</td>
</tr>
';
}

echo '</table>';

 

 

I don't know where to start with applying the function  that was requested to use above when I take the while out only one record appears.

 

could anyone give me some help.

//$bg = '#eeeeee'; // Set the background color.
while ($row = mysql_fetch_array($result)) {
   // no longer needed with the score choosing $bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee'); // Switch the background color.
   
   echo '<tr class="' . changeCssScore($row['score']) . '">
      <td align="left">' . $row['player'] . '</td>
      <td align="left">' . $row['school'] . '</td>
      <td align="left">' . $row['score'] . '</td>
   </tr>
   ';
}

echo '</table>';

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.