Re: online score board tally
To accomplish this project, your going to need to know a bit of javascript for the right click. What would be easier is just to have 2 buttons (Add and Subtract).
Assuming you have access to mysql, i would use that instead of a text file.
Re: online score board tally
do you have an example project you can show me???
Re: online score board tally
this is a little messy, but gets done what you want to get done. but, I've stored everything in the query string (whereas you would probably want to store things in a database or text file for convenience). you'd only need to change the way the $scores array is built to change this, and the way that the +/- links function.
PHP Code:
<style type="text/css">
* { font-size: 10pt; font-family: verdana; }
a { text-decoration: none; }
table { border: 0; padding: 0; }
td { border: 1px solid #000; width: 50px; height: 50px; text-align: center; }
td em { font-style: normal; font-size: 14pt; }
.black { background: #000; color: #fff; text-align: right; }
.name { width: 150px; padding-right: 5px; }
.vname { height: 150px; padding-top: 5px; padding-bottom: 10px; text-align: center; line-height: 10pt; }
</style>
<table>
<?php
$players = array("david", "robert", "patrick", "nathan", "barbie"); //5 total players
$scores = array();
//grab values from GET if there are any, otherwise default to 0
for($y = 0; $y < count($players); $y++){
for($x = 0; $x < count($players); $x++){
$c = $y . '-' . $x;
$scores[$y][$x] = (isset($_GET[$c])) ? $_GET[$c] : 0;
}}
for($i = 0; $i < count($players); $i++){
//y
?>
<tr>
<td class="black name"><?php echo $players[$i]; ?></td>
<?php
for($j = 0; $j < count($players); $j++){
//x
if($j == $i){
//players can't play themselves
?>
<td class="black"> </td>
<?php
}else{
$q = getenv("QUERY_STRING");
$coord = $i . '-' . $j;
$fndq = $coord . "=" . $scores[$i][$j];
$addq = $coord . "=" . ($scores[$i][$j] + 1); //this is what we're adding to the query string
$subq = $coord . "=" . ($scores[$i][$j] - 1); // ''
//if there's already this variable in the query string, we want to replace it rather than append to it
if(strpos($q, $fndq) === false){
$aq = $q . "&" . $addq;
$sq = $q . "&" . $subq;
}else{
$aq = str_replace($fndq, $addq, $q);
$sq = str_replace($fndq, $subq, $q);
}
?>
<td><a href="?<?php echo $aq; ?>">+</a> <em><?php echo $scores[$i][$j]; ?></em> <a href="?<?php echo $sq; ?>">-</a></td>
<?php
}
}
?>
</tr>
<?php
}
?>
<tr>
<td> </td>
<?php
for($n = 0; $n < count($players); $n++){
?>
<td class="black vname" valign="top"><?php for($l = 0; $l < strlen($players[$n]); $l++){ echo $players[$n][$l] . "<br />"; } ?></td>
<?php
}
?>
</tr>
</table>
in action: http://davidmiles.ca/php/players.php
since you're new to PHP, I would definitely recommend that you don't just 'take' this -- but instead, look up the functions used at PHP.net and make sure you understand what's going on in the script. if you have any questions, post them.
edit: fixed a small error.
Re: online score board tally
Nice work Kows. Except it gives negative values for scores.
But nice.
Re: online score board tally
well, no where in his post did he say that negative scores were undesirable, so I don't see why you might think that's a bad thing.
Re: online score board tally
Thanks Kows, That is exactly what I am after, ont have time now to look at the code, but quick question, If the person on the left of the grid is the winner Is it possible to add a total wins and losses at the end of each persons name?
Re: online score board tally
sure. you just need to make an array tally up the scores as the loop runs. I can give you a quick example in a little bit, I'll post another reply when I can.
Re: online score board tally
so, when I had a chance to sit down and actually look at this, it seems like it would much harder to adapt the script I made to do what you wanted with wins/losses than I had originally thought. using a database would be much easier and much more efficient.
now, so that I can get a bit more detail from you, would it not make more sense to completely eliminate the minus sign ("-") from the grid if the person on the left is always the winner? because, for example, if home is on the left and the bottom is away:
Code:
David (home) vs Robert (away) -> hitting + would give David a win
Robert (home) vs David (away) -> hitting - should give David a win
it doesn't really make sense to have two separate areas on the same grid to give David a win.
I can write some code that should get you on the way to using a database for this, though I won't go through the hassle of a text file.