Jump to content

Help with School Scoreboard


mightymouse

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>';

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.