-
Posts
24 -
Joined
-
Last visited
Never
Profile Information
-
Gender
Male
Jorn's Achievements

Newbie (1/5)
0
Reputation
-
Worked like a charm! thanks
-
Hey guys, Im trying to make a scoreboard for my pokersite so see who is the best player at the moment. I calculate this by counting the total points for a player earned this season, and devide it by the rounds played. This works well only I can't seem to figure out how to sort the table on the average score (points devided by rounds played). since the sorting at current code is done on a SQL column, I was wondering if it is possible to change that. The code automaticly adds nummers to the rows to see who i 1 through 6. here is the relevant code part: { // SELECT * FROM ".$score_table." WHERE tournamentid = '" . $cgi->htmlEncode ( $row [ "tournamentid" ] ) . "' ORDER BY points DESC $rows = $sql->execute ( "SELECT playerid,SUM(points) AS points,count(playerid) AS ronden FROM ".$score_table." GROUP BY playerid ORDER BY points DESC", SQL_RETURN_ASSOC ) or die ("$DatabaseError"); echo "<table border=\"1\" align=\"center\" cellpadding=\"4\" cellspacing=\"1\" bgcolor=\"#000000\" bordercolor=\"#e17400\"> <tr bgcolor=\"#000000\" bordercolor=\"#e17400\"><td>Positie</td><td>Poker King</td><td>Punten totaal</td><td>Gespeelde ronden</td><td>Gemiddelde</td></tr>"; $num = sizeof ( $rows ); for ( $i = 0; $i < $num; ++$i ) { $ronden = $rows [ $i ] [ "ronden" ]; $points = $rows [ $i ] [ "points" ]; $playerid = $rows [ $i ] [ "playerid" ]; $gem = round($points/$ronden,2); $pos = $i + 1; echo "<tr bgcolor=\"#000000\"> <td align=\"center\" >$pos</td> <td>"; $sql->execute ( "SELECT playerid FROM ".$player_table." AS playerid", SQL_RETURN_ASSOC ); $prow = $prows [ 0 ]; if ($prow['profile']) { echo "<a href=\"?op=showplayer&pid=$playerid\" title=\"View Player Information\" >$prow[name]</a>"; } else { echo "$prow[name]"; } echo"$playerid</td> <td align=\"center\" >$points</td> <td align=\"center\" >$ronden</td> <td align=\"center\" >$gem</td> </tr>"; } echo "</table>"; } } here is the result: As you can see player 6 should be at position 5. p.s. sorry for the dutch column names translation: Positie = Position , punten totaal = total points , Gespeelde ronden = rounds played , gemiddelde = average
-
well I can understand you guys are done investing time in this project And the main goal is accoplished! I can add multiple players to a tournament in one go! So the checking for double isnt working and I get the message displayed multiple times but thats no big deal really. Special thanks to Creata.Physics for his huge help and great examples, sure learned alot this week Bought a PHP book today so going to study the matter some more, who knows I might someday be able to help others here! anyway thanks again!
-
echo $player_store . '<br/>'; gives no names back so indeed the array isnt functioning. If i put the echo higher in the code on Player_id i get only the first selected name back. so indeed the array isnt picking up the names as it should.
-
no errors on loading page with the first suggestion (i didnt implement your suggesions yet on the second codeblock since i first want to get it working as is). however: No details found, please try again later array empty in your code?
-
yes i tried but it doesnt fire off correcly indeed like you concluded since the success message fires even before the submit taken place now with error obviously. Im trying to grasp the concept but its hard for me. just finished 5 day course of SQL and am now trying to learn PHP but its hard (but fun!), please bare with me in my ignorance full dump with implemented changes suggested earlier: <?php include "../includes/config.php"; if (isset($_COOKIE["ValidUserAdmin"])) { require ( "../includes/CGI.php" ); require ( "../includes/SQL.php" ); $cgi = new CGI (); $sql = new SQL ( $DBusername, $DBpassword, $server, $database ); if ( ! $sql->isConnected () ) { die ( $DatabaseError ); } ?> <html> <head> <title>PokerMax Poker League :: The Poker Tournamnet League Solution</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link href="../includes/style.css" rel="stylesheet" type="text/css" /> </head> <body bgcolor="#F4F4F4"> <?PHP include ("header.php"); ?> <table width="100%" cellpadding="5" cellspacing="0" border="0"> <tr> <td valign="top" bgcolor="ghostwhite" class="menu"><?PHP include ("leftmenu.php"); ?></td> <td bgcolor="#FFFFFF"> </td> <td valign="top" align="left" width="100%" bgcolor="#000000"><h1><br /> <img src="images/home.gif" width="25" height="25" /> PokerMax Poker League :: <font color="#CC0000">Assign Players to Tournaments</font></h1> <br /> <p>If you are running multiple tournaments on your website, this feature will allow you to assign any of your players to tournaments which you are running.</p> <?php if ( $cgi->getValue ( "op" ) == "AssignPlayer" ) { foreach($cgi->getValue('playerid') as $player_id) { $result = mysql_query("SELECT playerid FROM {$score_table} WHERE playerid = '". $sql->quote( $player_id ) ."' AND tournamentid = '" . $sql->quote ( $cgi->getValue ( "tournamentid" ) ) . "'") or die ("$DatabaseError"); $chkd_email = mysql_numrows($result); if ($chkd_email != "") { print "<p class=\"red\"><strong>The Player has already been assigned to this tournament</strong></p>"; } else { mysql_query("INSERT INTO ".$score_table." VALUES ( '', " . $sql->quote ( $player_id ) . ", " . $sql->quote ( $cgi->getValue ( "tournamentid" ) ) . ", '0', '$dateadded' )") or die ("$DatabaseError"); } } } $playerid = $cgi->getValue('playerid'); if( isset( $playerid ) ) { $player_list = implode( ',', $cgi->getValue('playerid') ); $players_added = "<p align='center' class='red'>The player(s): <strong>$player_list</strong> have been assigned to the poker tournament.</p>";} ?> <br> <?php echo $players_added; ?> <form method="post"> <input name="op" type="hidden" value="AssignPlayer"> <select name="playerid[]" selected multiple="multiple" size="6"> <?PHP $rows = $sql->execute ( "SELECT * FROM " . $player_table . " ORDER BY playerid ASC", SQL_RETURN_ASSOC ); for ( $i = 0; $i < sizeof ( $rows ); ++$i ) { $row = $rows [ $i ]; ?> <option value="<?php echo $cgi->htmlEncode ( $row [ "playerid" ] ); ?>"> <?php echo $cgi->htmlEncode ( $row [ "playerid" ] ); ?> - <?php echo $cgi->htmlEncode ( $row [ "name" ] ); ?> </option> <?php } ?> </select> <em>and assign to the tournament =></em> <select name="tournamentid" size="1"> <option value="">Select Tournament ....</option> <?PHP $rows = $sql->execute ( "SELECT * FROM " . $tournament_table . " ORDER BY id DESC", SQL_RETURN_ASSOC ); for ( $i = 0; $i < sizeof ( $rows ); ++$i ) { $row = $rows [ $i ]; ?> <option value="<?php echo $cgi->htmlEncode ( $row [ "tournamentid" ] ); ?>"> <?php echo $cgi->htmlEncode ( $row [ "tournament_name" ] ); ?> </option> <?php } ?> </select> <input type="submit" value="Assign Player" ONCLICK="return confirm('Are you sure you want to add this player to the tournament?');" /> </form> <br /></td> </tr> </table> <?PHP include ("footer.php"); ?> </body> </html> <?php } else { header("Location: index.php"); exit; } ?> UPDATE: put the <br> <?php echo $players_added; ?> AFTER the POST now and then it doesnt fire before the submit, however the error still shows on loading the page: Warning: implode(): Invalid arguments passed in /httpd.www/poker/pokeradmin/players-to-tournaments.php on line 60
-
changed it into: if( isset( $cgi->getValue['playerid'] ) ) according to the php manual i need to use [] instead of () for isset and empty. but then when i select 2 names (yes it loads without errors) it gives: No details found, please try again later this means the array is now empty I think? With your suggestion: replace $players_added = ''; if( isset( $cgi->getValue['playerid'] ) ) with $playerid = $cgi->getValue('playerid'); if( isset( $playerid ) ) when i load the page, even before i selected any names the follow appears above the selection box: Warning: implode(): Invalid arguments passed in httpd.www/poker/pokeradmin/players-to-tournaments.php on line 60 The player(s): have been assigned to the poker tournament. line 60 holds $player_list = implode( ',', $cgi->getValue('playerid') );
-
Thanks for the update Creata.physics! added the code and then replaced the echo with the one you suggested. on loading the page i get white page with: Fatal error: Can't use method return value in write context in /httpd.www/poker/pokeradmin/players-to-tournaments.php on line 58 line 58: if( isset( $cgi->getValue('playerid') ) )
-
Have to get some sleep now, not seeing straight anymore (1:30 am here in Netherlands). Ill continue this in the morning thanks for all the help sofar! made some real progress
-
Well been reading for long time actually but obviously not long enough haha tried your new code but it does something odd: when I start the page without even selecting a player I get a warning: The player Warning: implode(): Invalid arguments passed in /httpd.www/poker/pokeradmin/players-to-tournaments.php on line 164 has been assigned to the poker tournament Line 164 holds the Implode obviously. (its 164 when I copy paste your code it adds loads of spaces in lines for some reason). when I select some players and hit ADD , I get: no players where found. Try again later
-
Tried that but still get the extra lines from the loop: <p align="center" class="red">The player <strong><?php echo implode(", ",$playerid); ?></strong> has been assigned to the poker tournament.</p> results in: Also i note the the double add check is not working anymore and i can add same player more then once... current code: <?php include "../includes/config.php"; if (isset($_COOKIE["ValidUserAdmin"])) { require ( "../includes/CGI.php" ); require ( "../includes/SQL.php" ); $cgi = new CGI (); $sql = new SQL ( $DBusername, $DBpassword, $server, $database ); if ( ! $sql->isConnected () ) { die ( $DatabaseError ); } ?> <html> <head> <title>PokerMax Poker League :: The Poker Tournamnet League Solution</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link href="../includes/style.css" rel="stylesheet" type="text/css" /> </head> <body bgcolor="#F4F4F4"> <?PHP include ("header.php"); ?> <table width="100%" cellpadding="5" cellspacing="0" border="0"> <tr> <td valign="top" bgcolor="ghostwhite" class="menu"><?PHP include ("leftmenu.php"); ?></td> <td bgcolor="#FFFFFF"> </td> <td valign="top" align="left" width="100%" bgcolor="#000000"><h1><br /> <img src="images/home.gif" width="25" height="25" /> PokerMax Poker League :: <font color="#CC0000">Assign Players to Tournaments</font></h1> <br /> <p>If you are running multiple tournaments on your website, this feature will allow you to assign any of your players to tournaments which you are running.</p> <?php if ( $cgi->getValue ( "op" ) == "AssignPlayer" ) { foreach($cgi->getValue('playerid') as $player_id) { //echo $player_id . '<br/>'; $result = mysql_query("SELECT playerid FROM ".$score_table." WHERE playerid = " . $sql->quote ( $cgi->getValue ( "playerid" ) ) . " AND tournamentid = " . $sql->quote ( $cgi->getValue ( "tournamentid" ) ) . "") or die ("$DatabaseError"); $chkd_email = mysql_numrows($result); if ($chkd_email != "") { print "<p class=\"red\"><strong>The Player has already been assigned to this tournament</strong></p>"; } else { } mysql_query("INSERT INTO ".$score_table." VALUES ( '', " . $sql->quote ( $player_id ) . ", " . $sql->quote ( $cgi->getValue ( "tournamentid" ) ) . ", '0', '$dateadded' )") or die ("$DatabaseError"); ?> <br> <p align="center" class="red">The player <strong><?php echo implode(", ",$playerid); ?></strong> has been assigned to the poker tournament.</p> <?php } } ?> <form method="post"> <input name="op" type="hidden" value="AssignPlayer"> <select name="playerid[]" selected multiple="multiple" size="6"> <?PHP $rows = $sql->execute ( "SELECT * FROM " . $player_table . " ORDER BY playerid ASC", SQL_RETURN_ASSOC ); for ( $i = 0; $i < sizeof ( $rows ); ++$i ) { $row = $rows [ $i ]; ?> <option value="<?php echo $cgi->htmlEncode ( $row [ "playerid" ] ); ?>"> <?php echo $cgi->htmlEncode ( $row [ "playerid" ] ); ?> - <?php echo $cgi->htmlEncode ( $row [ "name" ] ); ?> </option> <?php } ?> </select> <em>and assign to the tournament =></em> <select name="tournamentid" size="1"> <option value="">Select Tournament ....</option> <?PHP $rows = $sql->execute ( "SELECT * FROM " . $tournament_table . " ORDER BY id DESC", SQL_RETURN_ASSOC ); for ( $i = 0; $i < sizeof ( $rows ); ++$i ) { $row = $rows [ $i ]; ?> <option value="<?php echo $cgi->htmlEncode ( $row [ "tournamentid" ] ); ?>"> <?php echo $cgi->htmlEncode ( $row [ "tournament_name" ] ); ?> </option> <?php } ?> </select> <input type="submit" value="Assign Player" ONCLICK="return confirm('Are you sure you want to add this player to the tournament?');" /> </form> <br /></td> </tr> </table> <?PHP include ("footer.php"); ?> </body> </html> <?php } else { header("Location: index.php"); exit; } ?>
-
if i change the INSERT INTO: " . $sql->quote ( $player_id ) . ", and leave the bracket as in last post, and then select 4 names it adds the names to the tournament as selected, only the confirmation text says ARRAY instead of the actual player name.. however it does add the names!! and the names are the correct ID since when i add points to an added name it calculates them in the leaderboard at the correct person! so changed <p align="center" class="red">The player <strong><?php echo $_POST['playerid']; ?></strong> has been assigned to the poker tournament.</p> to ?> <br> <p align="center" class="red">The player <strong><?php echo $player_id; ?></strong> has been assigned to the poker tournament.</p> <?php And that replaces the ARRAY with the player name selected, only problem is that it makes a line for each player (for the loop). But the array finally works! Thanks so much oh one final thing while we on the topic, is there a way to select all players at once or all players by default are selected when the page loads?
-
so If i roll back to the last code before the one you posted and put the bracket just above the insert into statement, and then select 3 players and add them it actually does add 3 players, but all are named array. if i retry with 2 players it adds 2 players named array. if ($chkd_email != "") { print "<p class=\"red\"><strong>The Player has already been assigned to this tournament</strong></p>"; } else { } mysql_query("INSERT INTO ".$score_table." VALUES ( so the closing bracket of the array is now just below ELSE. probably not helpfull hahah but interesting to see that it sees the number of persons i selected and adds that number to the tournament only without the actual names selected (while the ECHO does show the correct names).
-
Thanks for your swift reply! copy pasted your code and send it to the server. Page loads fine, I select 3 names and click add. I get : No details found, please try again later and when I check the tournament its completely empty (so not player named Array is added either). so to test i put the echo back in echo $player_id . '<br/>'; and I run it, the echo only returns the first name selected (but does not add it like stated above).
-
I notice that you both have a somewhat different foreach statement. Drummin: foreach($_POST['playerid'] as $playerid){ Result: no names are printed back to me on the Echo player_id. Creata.Physics: foreach($cgi->getValue('playerid') as $player_id){ Result: get names back in the Echo. Therefor I used Creata.physics foreach statement, correct me if I made a wrong conclusion here. anyway I played around with the placing of the end of the loop bracket and this is the result sofar. when I select 3 players and add them I get: the tournament content then shows: think im not setting the end of the arrayloop correctly? I got it just before the ending of the PHP end ( like Drummin suggested after the Insert Into statement): '$dateadded' )") or die ("$DatabaseError"); } ?> The code now looks like this: <?php include "../includes/config.php"; if (isset($_COOKIE["ValidUserAdmin"])) { require ( "../includes/CGI.php" ); require ( "../includes/SQL.php" ); $cgi = new CGI (); $sql = new SQL ( $DBusername, $DBpassword, $server, $database ); if ( ! $sql->isConnected () ) { die ( $DatabaseError ); } ?> <html> <head> <title>PokerMax Poker League :: The Poker Tournamnet League Solution</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link href="../includes/style.css" rel="stylesheet" type="text/css" /> </head> <body bgcolor="#F4F4F4"> <?PHP include ("header.php"); ?> <table width="100%" cellpadding="5" cellspacing="0" border="0"> <tr> <td valign="top" bgcolor="ghostwhite" class="menu"><?PHP include ("leftmenu.php"); ?></td> <td bgcolor="#FFFFFF"> </td> <td valign="top" align="left" width="100%" bgcolor="#000000"><h1><br /> <img src="images/home.gif" width="25" height="25" /> PokerMax Poker League :: <font color="#CC0000">Assign Players to Tournaments</font></h1> <br /> <p>If you are running multiple tournaments on your website, this feature will allow you to assign any of your players to tournaments which you are running.</p> <?php if ( $cgi->getValue ( "op" ) == "AssignPlayer" ) { foreach($cgi->getValue('playerid') as $player_id) { echo $player_id . '<br/>'; $result = mysql_query("SELECT playerid FROM ".$score_table." WHERE playerid = " . $sql->quote ( $cgi->getValue ( "playerid" ) ) . " AND tournamentid = " . $sql->quote ( $cgi->getValue ( "tournamentid" ) ) . "") or die ("$DatabaseError"); $chkd_email = mysql_numrows($result); if ($chkd_email != "") { print "<p class=\"red\"><strong>The Player has already been assigned to this tournament</strong></p>"; } else { mysql_query("INSERT INTO ".$score_table." VALUES ( '', " . $sql->quote ( $cgi->getValue ( "playerid" ) ) . ", " . $sql->quote ( $cgi->getValue ( "tournamentid" ) ) . ", '0', '$dateadded' )") or die ("$DatabaseError"); } ?> <br> <p align="center" class="red">The player <strong><?php echo $_POST['playerid']; ?></strong> has been assigned to the poker tournament.</p> <?php } } ?> <form method="post"> <input name="op" type="hidden" value="AssignPlayer"> <select name="playerid[]" multiple="multiple" size="6"> <?PHP $rows = $sql->execute ( "SELECT * FROM " . $player_table . " ORDER BY playerid ASC", SQL_RETURN_ASSOC ); for ( $i = 0; $i < sizeof ( $rows ); ++$i ) { $row = $rows [ $i ]; ?> <option value="<?php echo $cgi->htmlEncode ( $row [ "playerid" ] ); ?>"> <?php echo $cgi->htmlEncode ( $row [ "playerid" ] ); ?> - <?php echo $cgi->htmlEncode ( $row [ "name" ] ); ?> </option> <?php } ?> </select> <em>and assign to the tournament =></em> <select name="tournamentid" size="1"> <option value="">Select Tournament ....</option> <?PHP $rows = $sql->execute ( "SELECT * FROM " . $tournament_table . " ORDER BY id DESC", SQL_RETURN_ASSOC ); for ( $i = 0; $i < sizeof ( $rows ); ++$i ) { $row = $rows [ $i ]; ?> <option value="<?php echo $cgi->htmlEncode ( $row [ "tournamentid" ] ); ?>"> <?php echo $cgi->htmlEncode ( $row [ "tournament_name" ] ); ?> </option> <?php } ?> </select> <input type="submit" value="Assign Player" ONCLICK="return confirm('Are you sure you want to add this player to the tournament?');" /> </form> <br /></td> </tr> </table> <?PHP include ("footer.php"); ?> </body> </html> <?php } else { header("Location: index.php"); exit; } ?>