|
-
Nov 3rd, 2008, 06:11 PM
#1
Thread Starter
Hyperactive Member
online score board tally
Hi Guys, I have webspace that will allow me to use php and everything, I have no restrictions from the server, so what i want to do can be done in the simplest way possible, whatever that may be...
Basically I want to build a scoreboard
I want a simple grid system, with names of players on the x and y axis, and the relevent squares greyed out so that a player cant play himself. I was hoping to have it so that if you left click in the box, it adds 1 to the total of that box, then if you right click it removes 1.
Has anyone got or done or know how to do something like this. I think the way to do it is to make a table in html then in each square of the table have a little line of php that when clicked, it adds 1 to a variable saved in a notepad file, and displays that variable in its place. Please can someone help me here. I am very very new to php.
Is this the way to do it?
Thanks
-
Nov 3rd, 2008, 07:41 PM
#2
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.
My usual boring signature: Something
-
Dec 30th, 2008, 03:51 PM
#3
Thread Starter
Hyperactive Member
Re: online score board tally
do you have an example project you can show me???
-
Dec 30th, 2008, 04:59 PM
#4
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.
Last edited by kows; Dec 30th, 2008 at 05:04 PM.
-
Dec 30th, 2008, 06:43 PM
#5
Re: online score board tally
Nice work Kows. Except it gives negative values for scores.
But nice.
My usual boring signature: Something
-
Dec 30th, 2008, 07:11 PM
#6
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.
-
Jan 2nd, 2009, 03:19 PM
#7
Thread Starter
Hyperactive Member
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?
-
Jan 3rd, 2009, 01:12 AM
#8
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.
-
Jan 3rd, 2009, 04:11 AM
#9
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|