Jump to content

Multiselect and add


Jorn

Recommended Posts

Hi guys,

 

Im using a poker league script to keep track of the home games me and my 5 friends play every month.

This script works fine, but its kinda tendeous because when I make a round I have to manually add every player individualy.

 

I edited the html so that I get a multiselect box where all the names are listed and can be multiselected, but the code only saves the first name and thus it does not work as intended.

 

anyone got any idea how to change this so I can select multiple names and they are added all at once?

 

here is how the page looks:

206g878.jpg

 

this is the add-players-to-tournament.php:

<?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 Tournament 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" )
  {

  $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 size="8">

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

Link to comment
Share on other sites

I'm pretty sure you need to use:

<select multiple="multiple" name="playerid[]">

To select select multiple values.

 

Then submit the form, with

print_r($_POST);
eixt();

at the beginning of the statement to make sure you get the data you expect.

Afterwards remove it so you can get back to your project.

 

Link to comment
Share on other sites

Hi Creata.physics,

 

I changed

?>
<form method="post">
<input name="op" type="hidden" value="AssignPlayer">
<select name="playerid" multiple size="8">
<?PHP 

 

to

?>
<form method="post">
<input name="op" type="hidden" value="AssignPlayer">
<select multiple="multiple" name="playerid" multiple size="8">
<?PHP 

 

this doesnt give any errors but only still adds the last person selected (in a multiselect) to the tournament, same as before.

So this does not solve the problem im facing.

 

any other ideas?

 

oh and when i use name="playerid[]" instead of name="playerid" is adds a player named ARRAY to the tournament.

Link to comment
Share on other sites

But how do I handle this array to pick up the names selected?

 

as is added in my last post "when i use name="playerid[]" instead of name="playerid" is adds a player named ARRAY to the tournament."

 

so i guess i need to define it somehow but not sure how?

Link to comment
Share on other sites

I've never worked with this object style scripting before so I may not have this right.  Normally I would just do a foreach statement and build the insert code.  I'm sure others will have a better option for you.

<?php 
$insert="";
$i=1;	
$count=count($sql->quote ( $cgi->getValue ( "playerid" ) ));
foreach($sql->quote ( $cgi->getValue ( "playerid" ) ) as $playerid){ 
$insert.="('','$playerid'," . $sql->quote ( $cgi->getValue ( "tournamentid" ) ) . ",'0','$dateadded')";
if ($i<$count){
$insert.=",";
}
$i++;
}
mysql_query("INSERT INTO ".$score_table." VALUES $insert") or die ("$DatabaseError"); 
?>

Link to comment
Share on other sites

I'm pretty sure you need to use:

<select multiple="multiple" name="playerid[]">

To select select multiple values.

 

Then submit the form, with

print_r($_POST);
eixt();

at the beginning of the statement to make sure you get the data you expect.

Afterwards remove it so you can get back to your project.

 

Link to comment
Share on other sites

thanks Drummin,

 

I replaced in the script (thought that was the idea):

<?php

  if ( $cgi->getValue ( "op" ) == "AssignPlayer" )
  {

  $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"); 
    ?>

with your code.

 

however now I get the error : Warning: Invalid argument supplied for foreach() in httpd.www/poker/pokeradmin/players-to-tournaments.php on line 38

line 38 holds

foreach($sql->quote ( $cgi->getValue ( "playerid" ) ) as $playerid){ 

 

the form method has  the array

<form method="post">
<input name="op" type="hidden" value="AssignPlayer">
<select name="playerid[]" multiple="multiple" size="6">

 

what am I missing? :) And thanks for the help sofar!

Link to comment
Share on other sites

We need to make sure we are getting the correct data that you expect to recieve after selecting a few users names.

 

So lets say we chose, Rob and Bob.

Well, we need to make sure the playerid array we created contains Rob and Bob's identification numbers( ids ).

 

So to check and make sure we got the correct output, we will "dump" all post data, to make sure the form is submitting information accurately.

You should have a code that handles the form being processed, it looks like it's this statement:

  if ( $cgi->getValue ( "op" ) == "AssignPlayer" )
  {

So after that, we are going to add:

print_r($_POST); // This is unaltered post data, hopefully
print_r($cgi->getValue('playerid')); // This should be the same as $_POST['playerid'], if not, we found our starting point of our issue
exit(); // this is so we don't insert or update any data in case our post data is NOT accurate.

 

After that, you may get code that looks like this:

Array
(
)

Let us know if that array is empty, otherwise, post whatever print_r outputs over here so we can further assist you.

Link to comment
Share on other sites

Hi Creata.physics,

 

For clearance I undid the code suggestion by Drummin for this test and just added the Print commands. (and ofcourse added playerid[] to select name). I had to leave out:

 

Array
(
)

It gave me an error (Parse error: syntax error, unexpected T_VARIABLE in /httpd.www/poker/pokeradmin/players-to-tournaments.php on line 45) on line 45 (line right after the above code sniplet).

 

I then selected 2 players (Foldman & Madmeijs) from the multiselect box and pressed asign to tournament.

Results on page:

 

Array ( [op] => AssignPlayer [playerid] => Array ( [0] => Foldman [1] => Madmeijs ) [tournamentid] => 300412184957 ) Array ( [0] => Foldman [1] => Madmeijs )

Link to comment
Share on other sites

Okay, I had you dump the $_POST data as well as using your $cgi class to find out if it returned the proper data with the correct array structure which it does.

So on the sumission of data, you'll loop though your playerid[] array to find out each username. Why you have it called playerid when the id is not the value is no business of mine. Anyway, here is how you'll use the data returned to benefit your situation:

foreach($cgi->getValue('playerid') as $player_id)
{
    echo $player_id . '<br/>'; // This should give you an idea on what needs to be done next
}

Link to comment
Share on other sites

Ok so I added the code to replace the print code from earlier.

 

somehow the array is not writing correctly.

 

select 3 players to add to tournament:

2nrou52.jpg

 

submit 3 players to add to tournament:

349b1gg.jpg

 

tournament holds the following players:

acef4x.jpg

Link to comment
Share on other sites

Seems that the 3 names selected are picked up by the array and printed on screen but the actual submit sends "Array" as player name to the database instead of the array selected names. I been messing about with the code but no luck yet. ill keep ya posted.

Link to comment
Share on other sites

But how do I handle this array to pick up the names selected?

 

as is added in my last post "when i use name="playerid[]" instead of name="playerid" is adds a player named ARRAY to the tournament."

 

so i guess i need to define it somehow but not sure how?

Th code I posted was not meant to replace your code, but was directly answering this question of how you handle the array.  You'll want do your query "like you had" to check for players within this foreach loop and then make your insert.  So again a basic example is.

foreach($_POST['playerid'] as $playerid){

//Do your query

//Handle the results

//Insert to DB

}// end of foreach loop

Link to comment
Share on other sites

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:

 

3478vi9.jpg

 

the tournament content then shows:

acef4x.jpg

 

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

Link to comment
Share on other sites

See if it works using 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)
{    


$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 $player_id has already been assigned to this tournament</strong></p>";
}
else {

  mysql_query("INSERT INTO ".$score_table." VALUES (
'',
" . $player_id . ",
" . $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;
  }
?>

 

What you were doing inserting the array $_POST['playerid'] to the playerid field of the database. You need to loop though $_POST['playerid'] as it is an array to get the values you are needed.

 

What I did was end the foreach loop before your success message gets shown. I also changed your query that inserts new data into the database by actually assigning the appropriate value to the playerid field.

 

Try that code, see if it works. If it doesn't, come back and we'll go from there.

Link to comment
Share on other sites

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).

 

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

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).

 

282p8co.jpg

 

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? :)

Link to comment
Share on other sites

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:

54xjd2.jpg

 

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

Link to comment
Share on other sites

Take some time into reading about arrays and how to handle them.

<?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"); 
	}
}
}
?>
<br>
<p align="center" class="red">The player(s): <strong><?php  echo implode(',', $cgi->getValue('playerid') ); ?></strong> have been assigned to the poker tournament.</p>
<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;
  }
?>

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.