mightymouse Posted April 20, 2009 Share Posted April 20, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/154869-help-with-school-scoreboard/ Share on other sites More sharing options...
revraz Posted April 20, 2009 Share Posted April 20, 2009 Sounds simple enough. Use a variable for say the row color, and use a IF statement to set that variable based on the criteria you desire. Quote Link to comment https://forums.phpfreaks.com/topic/154869-help-with-school-scoreboard/#findComment-814511 Share on other sites More sharing options...
premiso Posted April 20, 2009 Share Posted April 20, 2009 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>'; Quote Link to comment https://forums.phpfreaks.com/topic/154869-help-with-school-scoreboard/#findComment-814513 Share on other sites More sharing options...
mightymouse Posted April 20, 2009 Author Share Posted April 20, 2009 So depending on the result the css class style would be bronze silver or gold these values I would need to write into my css file.. ie .bronze{background-color:#336699;} Quote Link to comment https://forums.phpfreaks.com/topic/154869-help-with-school-scoreboard/#findComment-814525 Share on other sites More sharing options...
revraz Posted April 20, 2009 Share Posted April 20, 2009 I would just do that part inline. Quote Link to comment https://forums.phpfreaks.com/topic/154869-help-with-school-scoreboard/#findComment-814958 Share on other sites More sharing options...
premiso Posted April 20, 2009 Share Posted April 20, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/154869-help-with-school-scoreboard/#findComment-814966 Share on other sites More sharing options...
mightymouse Posted April 23, 2009 Author Share Posted April 23, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/154869-help-with-school-scoreboard/#findComment-817155 Share on other sites More sharing options...
premiso Posted April 23, 2009 Share Posted April 23, 2009 //$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>'; Quote Link to comment https://forums.phpfreaks.com/topic/154869-help-with-school-scoreboard/#findComment-817353 Share on other sites More sharing options...
revraz Posted April 23, 2009 Share Posted April 23, 2009 And yet your Function does a inline edit... 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. Quote Link to comment https://forums.phpfreaks.com/topic/154869-help-with-school-scoreboard/#findComment-817359 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.