Page 1 of 1

using css styles for certain values in a mysql table

Posted: Thu Jan 29, 2009 6:18 am
by mighty
Hi guys

Im creating a scoreboard for our school were kids do an excersise and then input their name school gender and score
the table will be displayed descending by the score so the high score is top and so on.

here is the board im working on, you can only enter your name at the moment and this is working

http://www.igloo-design.org/php/example/exampleinfo.php

what I would like to know or get advice on is how to add css styles to the table dependant on what score they get.
so if they get a high score they would have a yellow table indicating a gold position.
if they recieve a good score they would have a silver or grey colur in the table.

hope this makes sense

can I just use php html and css or would I need to use javascript and or ajax


cheers :?:

Re: using css styles for certain values in a mysql table

Posted: Thu Jan 29, 2009 6:27 am
by mattpointblank
Simple if statements.

Code: Select all

 
if($score == 1000) {
    echo "<p class=\"highscore\">$score</p>";
}
if($score > 1000) {
    echo "<p class=\"superscore\">$score</p>";   
}
// etc
 

Re: using css styles for certain values in a mysql table

Posted: Thu Jan 29, 2009 9:54 am
by pickle
It's unlikely a user will get exactly 1000 or whatever a border condition is.

Code: Select all

<?PHP
$HIGHSCORE = 90;
$GOODSCORE = 70;
 
$cell_class = 'badscore';
if($student_score >= $GOODSCORE && $student_score < $HIGHSCORE)
   $cell_class = 'goodscore';
else if($student_score >= $HIGHSCORE)
   $cell_class = 'highscore';
 
echo '<td class = "',$cell_class,'" >',$student_score,'</td>';?>

Re: using css styles for certain values in a mysql table

Posted: Thu Jan 29, 2009 10:13 am
by mighty
cheers for that it looks and makes sense

I just have a problem with applying different syntax i should mabe go back and learn all the php stuff.

I can never be creative with the code. will try to use this on something simple