Jump to content

need some help with a primary school score board


mightymouse

Recommended Posts

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. :confused:

 

here is the code

http://www.igloo-design.org/score/phpcode.php

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

excellent thanks for all your help it works  :D

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


}

?>

Link to comment
Share on other sites

it is updating the table instantly 8)

 

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 }

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.