using css styles for certain values in a mysql table

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mighty
Forum Newbie
Posts: 4
Joined: Thu Jan 29, 2009 6:09 am

using css styles for certain values in a mysql table

Post 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 :?:
mattpointblank
Forum Contributor
Posts: 304
Joined: Tue Dec 23, 2008 6:29 am

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

Post 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
 
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

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

Post 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>';?>
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
mighty
Forum Newbie
Posts: 4
Joined: Thu Jan 29, 2009 6:09 am

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

Post 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
Post Reply