mightymouse Posted May 9, 2010 Share Posted May 9, 2010 Hello php community I'm new to writing php and have embarked on learning php by trying to create a scoreboard for our pupils to enter scores they achieve on different sports tasks, it will give pupils the chance to compete with each other and other schools. I have set up the board here and pupils can enter their details http://www.igloo-design.org/score/ What Im trying to achieve is to apply a CSS class to the table row depending on thescore achieved by the child which would be plain bronze silver and gold. I have attempted to do this but im getting all the classes in the same row just wondered if someone could help me out a little to understand what i have done worng and what i need to do. here is the code http://www.igloo-design.org/score/phpcode.php Quote Link to comment https://forums.phpfreaks.com/topic/201147-need-some-help-with-a-primary-school-score-board/ Share on other sites More sharing options...
litebearer Posted May 9, 2010 Share Posted May 9, 2010 I think your problem is that you are 'double' echoing the row tags. try changing your function to simply echo the color NOT the complete tag echo "gold"; etc etc Quote Link to comment https://forums.phpfreaks.com/topic/201147-need-some-help-with-a-primary-school-score-board/#findComment-1055316 Share on other sites More sharing options...
mightymouse Posted May 9, 2010 Author Share Posted May 9, 2010 should i be using echo or should it be something else im not sure what to do next Quote Link to comment https://forums.phpfreaks.com/topic/201147-need-some-help-with-a-primary-school-score-board/#findComment-1055323 Share on other sites More sharing options...
litebearer Posted May 9, 2010 Share Posted May 9, 2010 Try replacing your function with this... function get_background($score){ $my_color = "plain"; if($score = 100 ){ $my_color = "bronze"; } if ($score = 400){ $my_color = "silver"; } if ($score = 1000){ $my_color = "gold"; } return $my_color; } Quote Link to comment https://forums.phpfreaks.com/topic/201147-need-some-help-with-a-primary-school-score-board/#findComment-1055326 Share on other sites More sharing options...
mightymouse Posted May 9, 2010 Author Share Posted May 9, 2010 it works to some extent gives all the rows the gold CSS class the result of score must come within a range of values to achieve the each different class plain class would be from a score of 0-99 bronze class would be from a score of 100-399 silver class would be from a score of 400-999 gold class above 1000 Quote Link to comment https://forums.phpfreaks.com/topic/201147-need-some-help-with-a-primary-school-score-board/#findComment-1055327 Share on other sites More sharing options...
hansford Posted May 9, 2010 Share Posted May 9, 2010 Post your code, please. Quote Link to comment https://forums.phpfreaks.com/topic/201147-need-some-help-with-a-primary-school-score-board/#findComment-1055332 Share on other sites More sharing options...
mightymouse Posted May 9, 2010 Author Share Posted May 9, 2010 <?php include'includes/connenction.php'; function get_background($score){ $my_color = "plain"; if($score = 100 ){ $my_color = "bronze"; } if ($score = 400){ $my_color = "silver"; } if ($score = 1000){ $my_color = "gold"; } return $my_color; } $query = "SELECT * FROM highScore ORDER BY score DESC"; $result = @mysql_query ($query); // Run the query. // Table header. echo '<table width="664" border="0" class="data"> <tr class="header"> <td ><b>Player</b></td> <td ><b>School</b></td> <td ><b>score</b></td> </tr>'; while ($row = mysql_fetch_array($result)) { echo '<tr class="' .get_background($row['score']). '"> <td >' . $row['player'] . '</td> <td >' . $row['school'] . '</td> <td >' . $row['score'] . '</td> </tr> '; } echo '</table>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/201147-need-some-help-with-a-primary-school-score-board/#findComment-1055340 Share on other sites More sharing options...
litebearer Posted May 9, 2010 Share Posted May 9, 2010 new improved LOL function function get_background($score){ $my_color = "plain"; if($score > 99 AND $score <400){ $my_color = "bronze"; } if ($score >399 and $score<1000){ $my_color = "silver"; } if ($score >999){ $my_color = "gold"; } return $my_color; } Quote Link to comment https://forums.phpfreaks.com/topic/201147-need-some-help-with-a-primary-school-score-board/#findComment-1055342 Share on other sites More sharing options...
mightymouse Posted May 9, 2010 Author Share Posted May 9, 2010 excellent thanks for all your help it works while i have your attention when the form is submitted to insert the data into the table the form is submitted to another php page which at the end directs them back to the scoreboard why does the new data not appear is takes a refresh to make it appaer <?php include 'includes/connenction.php'; $player = $_POST['player']; $school = $_POST['school']; $score = $_POST['score']; if(!$_POST['submit']) { echo "please fill in the form"; header('Location: index.php'); } else { mysql_query("INSERT INTO highScore (`player`,`school`,`score`) VALUES('$player','$school','$score')") or die(mysql_error()); echo "User has been added"; header('Location: index.php'); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/201147-need-some-help-with-a-primary-school-score-board/#findComment-1055353 Share on other sites More sharing options...
litebearer Posted May 9, 2010 Share Posted May 9, 2010 You are welcome! As to the refresh issue, not really sure - I am simply an old guy who knows enough to be dangerous Quote Link to comment https://forums.phpfreaks.com/topic/201147-need-some-help-with-a-primary-school-score-board/#findComment-1055357 Share on other sites More sharing options...
mightymouse Posted May 9, 2010 Author Share Posted May 9, 2010 it is updating the table instantly more questions to do with the last post when i insert the data it just goes in and brings the scoreboard but does not echo the user has been added i could try to add different messages to be displayed depending on the score submitted Quote Link to comment https://forums.phpfreaks.com/topic/201147-need-some-help-with-a-primary-school-score-board/#findComment-1055364 Share on other sites More sharing options...
litebearer Posted May 9, 2010 Share Posted May 9, 2010 it really is echoing the message, its just that it is very very very quickly do the header that follows the message - so don't blink and you can probably see the message as a test simply put exit(); right after the message Quote Link to comment https://forums.phpfreaks.com/topic/201147-need-some-help-with-a-primary-school-score-board/#findComment-1055368 Share on other sites More sharing options...
ignace Posted May 9, 2010 Share Posted May 9, 2010 I really advise you some other mechanism then just enter-it-yourself-and-hope-you-are-honest as you can clearly see in the current table martinted tedbury 2147483647 That 2xxxxx.. is the maximum integer value. The person who did that probably entered something like 999999999999999999999 which turned it into a float in PHP and in to an INT in MySQL. Add some logic to prevent to add anything higher then X as I don't imagine your score going anywhere near 100,000 (or 10,000 for that matter) Quote Link to comment https://forums.phpfreaks.com/topic/201147-need-some-help-with-a-primary-school-score-board/#findComment-1055379 Share on other sites More sharing options...
mightymouse Posted May 9, 2010 Author Share Posted May 9, 2010 can i limit this number in phpmyadmin That was actually me! It would actually be teachers who would input the details i would have to put the form on a password protected page. but this is the start of my journey in writing php and this scoreboard thanks for the input. Quote Link to comment https://forums.phpfreaks.com/topic/201147-need-some-help-with-a-primary-school-score-board/#findComment-1055380 Share on other sites More sharing options...
litebearer Posted May 9, 2010 Share Posted May 9, 2010 html form field can have various attributes - http://www.w3.org/MarkUp/HTMLPlus/htmlplus_41.html RANGE This allows you to specify an integer range with the MIN and MAX attributes, e.g. MIN=1 MAX=100. Users can select any value in this range. Quote Link to comment https://forums.phpfreaks.com/topic/201147-need-some-help-with-a-primary-school-score-board/#findComment-1055383 Share on other sites More sharing options...
ignace Posted May 9, 2010 Share Posted May 9, 2010 can i limit this number in phpmyadmin That was actually me! It would actually be teachers who would input the details i would have to put the form on a password protected page. but this is the start of my journey in writing php and this scoreboard thanks for the input. The best would be to limit this at database level as other applications may in the future write to this database. However MySQL totally ignore's check()'s so your need to verify it at your application-level, like: if ($score > x) { error } Quote Link to comment https://forums.phpfreaks.com/topic/201147-need-some-help-with-a-primary-school-score-board/#findComment-1055391 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.