Adding points to a number of teams

Hi
I’m very new to php and don’t understand a lot of what I’m reading at the moment.

I have a form which shows 12 teams and has a drop down selector to pick a number from 0-7 (points won).

How do I get that form to add to each of the team’s total when I submit the form?

Any help would be appreciated.

Harlequeen

ok this is pretty simple so first you need to know the value of the select menu (drop down menu) and you need to assign each option a value also preferably 1 to 1, 2 to 2, ect. this also goes for the team drop down menu also, oh and both drop downs need ids and names, you need to make sure your form has an action and method (should be post) e.g. <form action=displayScore.php> then in displayScore.php you would have this:

//make variables
$_POST['team1']=$team1;
$_POST['team2']=$team2;
$_POST['team1score']=$team1Score;
$_POST['team2score']=$team2Score;
//write scores and corresponding teams
print "$team1 vs. $team2 $team1Score - $team2Score";

just so you know this works because when the form is submitted it submits a variable for each drop down equal to whatever value option the user choose, i initiated these by using $_POST to call the variables and save them under another more comfortable var name and then i just told php to print those scores in my own little format

hope this helps:)

im sorry i think i misunderstood your post the first time i replied in order to get the total for each team all you need to do is this if i understand you correctly
instead of two drop down make one for each team and make each value for the options 0-7 then your php would look something like this

$t1Score = $_POSt[t1Score]
//and so one in that fashion for each of the 12 teams
print "Team (name) total = $t1Score"
// you could even make a table if you wanted

now if you want users to be able add to this then you need to save the data into a database which would be more complicated

Thanks for your help.

Sorry, I didn’t make myself clear when I wrote this…

I have a database which holds 60 teams, divided up into 4 divisions. I can pull them out from the database using the division identifier and I have a select menu for the points showing 0-7. I also have a field called ‘points’ and one called ‘total points’. They all have a team ID number.

What I want to do is select the score for the game, and do that for each team before I submit the form for updating the database. If a team scores 4 or more, they will get 1 extra point, which I want to be done automatically when the scores are input.

I want the total points to be updated then to show the total, and the input points to be cleared. Ideally, I would like the points for that week to be stored for that week in the divisions with the team ID number.

I don’t know how to do this and would like some help to learn how to do it, bit by bit.

I’ve looked at arrays on line, but I just don’t get it really, and can’t seem to apply it to what I’m trying to do.

I’ve run a darts league for many years and would love to be able to implement this.

Any help would be greatly appreciated. I’m very willing to put the effort into learning if someone would spare me their time.

Thanks in advance

Here is the code I’m using to pull the info from the database to the input form



$query="SELECT teams.teamName, teams.team_id, teams.Points from teams LEFT JOIN contacts ON teams.teamName =contacts.teamName where contacts.division=1";


$result = mysql_query($query) or die(mysql_error());
//Loop through results and print the team names and  numbers in a table
while($row = mysql_fetch_array($result)){

	?>
	<form name="addresults" action="addresults.php" method="get"  target="_self">
	
	<TABLE BORDER="2" ><TR><TD WIDTH=20PX><?
	echo $row[ 'team_id']; ?></TD><TD WIDTH=180PX><?
	
	echo $row['teamName']; ?></TD><TD WIDTH=20PX><select name="Points" value="$team_id[]">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
</select></TD><TD WIDTH=20PX>
	<?

	echo $row['Points']; ?></TD></TR></TABLE><?

	//echo "<br />";

Seeing as your are unsteady with all of this - here is some advice.

Get a very simple version of what you want working in HTML so that you understand fully what you want PHP to produce on your behalf.

Create a page with just 2 teams, with just 3 point options and a simple submit button.

Make the method of the form GET and the action = “” (it’ll post back to itself)

at the top of the page add this:


<?php
if(isset($_GET)){
var_dump($_GET);
}

?>
// your forms down here

Now, you want to create ONE form with 2 SELECTS and 1 SUBMIT button, and correctly name the elements so that you can return $team1 =2 and $team2 = 3 am I right?

Then read this PHP Arrays and Forms Handling

Have a play with your simple form till you work out how to pass the scores for the two teams. THEN you will understand what you are going to be asking PHP to do for you, and we can move on to the next challenge…

OK, thanks

I will try that.

Harlequeen