Jump to content

Easier Way To Make Almost 80 Insert Boxes


Greysoul

Recommended Posts

  • Replies 95
  • Created
  • Last Reply

You should be able to just use the $greenclan and $redclan variables you already have. You could maybe put that into a hidden input like so:

echo "<input type='hidden' name='greenClan' value='".$greenclan."' />

And do the same for the $redclan so you have access to the clan names when you POST.You may also want to change the names of your inputs in your tables a little so you can keep the two clans separate. For instance:

...<td><input type='text' name='grnPlayer[]'... /></td><td><input type='text' name='grnScore[]'... /></td>......<td><input type='text' name='redPlayer[]'... /></td><td><input type='text' name='redScore[]'... /></td>...

Link to comment
Share on other sites

Your talking about the player's names right? Was it inserting those before you tried my changes? Make sure you're still using the select tags for player names, I forgot about that when I posted the name changes before.Post your new code.

Link to comment
Share on other sites

got it working again..now to back it up and start playing with names lol. do i need to create a brand new post for all reds and all greens seperately?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><body class="body"><head><link rel="stylesheet" type="text/css" href="styles.css" /></head> <?php include("weekselection.php"); ?> <br><br><?phpif (isset($_GET['match'])) {$matchid= $_GET['match'];} echo "<form id='insertmatch' name='insertmatch' method='post' action=''>";$clans=mysql_query("SELECT * FROM Schedule WHERE GameID='$matchid'");while($row=mysql_fetch_array($clans)){$greenclan = $row['Green'];$redclan = $row['Red'];$greenscore = $row['GreenS'];$redscore = $row['RedS'];echo "<table class='bigtable'><tr><td>";echo "<table class='table'><tr>";echo "<th class='th'>" . $row['Green'] .  " " . Score . "</th>"; echo "<th class='td'>" . "<input type='text' class='form' name='greens' id='greens' value='' size='2'>" . "</td>";echo "<th class='th' colspan='5'>" . "</th>";echo "</tr><tr><th class='th'>Player</th><th class='th'>Score</th><th class='th'>Kills</th><th class='th'>Deaths</th><th class='th'>Caps</th><th class='th'>Attempts</th><th class='th'>MVP</th></tr>";$playerdrop = mysql_query("SELECT * FROM Players WHERE ClanName='".$greenclan."'");if (!$playerdrop)  {  die('Could not connect: ' . mysql_error());  }$playerSelect = "<select class='form' name='player[]' id='select".$i."'>";$playerSelect.="<option value=''>" . "Player" . "</option>";while($green = mysql_fetch_array( $playerdrop )) {$playerSelect.="<option id='player".$i."' value=".$green['Player'].">".$green['Player']."</option>";}$playerSelect.="</select>";$i=0;do  {  $i++;echo "<tr>\n";echo "<td class='td'>\n";echo $playerSelect;echo "</td>\n";echo "<td class='td'><input class='form' type='text' name='score[]' id='score".$i."' value='' size='3'></td>\n";echo "<td class='td'><input class='form' type='text' name='kills[]' id='kills".$i."' value='' size='2'></td>\n";echo "<td class='td'><input class='form' type='text' name='deaths[]' id='deaths".$i."' value='' size='4'></td>\n";echo "<td class='td'><input class='form' type='text' name='caps[]' id='caps".$i."' value='' size='2'></td>\n";echo "<td class='td'><input class='form' type='text' name='attempts[]' id='attempts".$i."' value='' size='6'></td>\n";echo "<td class='td'><input class='form' type='radio' name='mvpradio[]' id='mvpradio".$i."' value='1'></td>\n";echo "</tr>\n";  }  while ($i<=5); echo "</table>";echo "</td>";echo "<td>";echo "</td>";echo "<td>";echo "<table class='table'><tr>";echo "<th class='th'>" . $row['Red'] .  " " . Score . "</th>"; echo "<th class='td'>" . "<input type='text' class='form' name='reds' id='reds' value='' size='2'>" . "</td>";echo "<th class='th' colspan='5'>" . "</th>";}echo "</tr><tr><th class='th'>Player</th><th class='th'>Score</th><th class='th'>Kills</th><th class='th'>Deaths</th><th class='th'>Caps</th><th class='th'>Attempts</th><th class='th'>MVP</th></tr>";$playerdrops = mysql_query("SELECT * FROM Players WHERE ClanName='".$redclan."'");if (!$playerdrops)  {  die('Could not connect: ' . mysql_error());  }$playerSelects = "<select class='form' name='player[]' id='select".$i."'>";$playerSelects.="<option value=''>" . "Player" . "</option>";while($red= mysql_fetch_array( $playerdrops )) {$playerSelects.="<option id='player".$i."' value=".$red['Player'].">".$red['Player']."</option>";}$playerSelects.="</select>";$i=0;do  {  $i++;echo "<tr>\n";//echo "<td class='td'><input class='form' type='text' name='player[]' id='player".$i."' value='' size='12'></td>\n";echo "<td class='td'>\n";echo $playerSelects;echo "</td>\n";echo "<td class='td'><input class='form' type='text' name='score[]' id='score".$i."' value='' size='3'></td>\n";echo "<td class='td'><input class='form' type='text' name='kills[]' id='kills".$i."' value='' size='2'></td>\n";echo "<td class='td'><input class='form' type='text' name='deaths[]' id='deaths".$i."' value='' size='4'></td>\n";echo "<td class='td'><input class='form' type='text' name='caps[]' id='caps".$i."' value='' size='2'></td>\n";echo "<td class='td'><input class='form' type='text' name='attempts[]' id='attempts".$i."' value='' size='6'></td>\n";echo "<td class='td'><input class='form' type='radio' name='mvpradio[]' id='mvpradio".$i."' value='1'></td>\n";echo "</tr>\n";  }  while ($i<=5);// while (++$tables <= 2); echo "</table>";echo "</td></tr><tr><td class='button' colspan='3'>";echo "<input type='Submit' value='Add Match' name='Submit'>";echo "</form>";echo "</td></tr>";?><tr><td><?phpif($_POST['Submit']){$index = 0;while (isset($_POST['player'][$index])) {$Player=$_POST['player'][$index];$Score=$_POST['score'][$index];$Kills=$_POST['kills'][$index];$Deaths=$_POST['deaths'][$index];$Caps=$_POST['caps'][$index];$Attempts=$_POST['attempts'][$index];$MVP=$_POST['mvpradio'][$index];$index++;$query="INSERT INTO Scorecard(ID, Player, Score, Kills, Deaths, Caps, Attempts, GameID, MVP)VALUES ('NULL','".$Player."','".$Score."','".$Kills."','".$Deaths."','".$Caps."','".$Attempts."','".$matchid."','".$MVP."')";mysql_query($query) or die ('Error updating database');}}if($_POST['Submit']==true){ echo "<meta http-equiv=\"refresh\" content=\"0;URL=scheduleedit.php?match=$matchid\">";} if($_POST['Submit']){$GreenS=$_POST['greens'];$RedS=$_POST['reds'];mysql_query("UPDATE Schedule SET GreenS='$GreenS', RedS='$RedS' WHERE GameID='$matchid'");}if($greenscore==0){echo "<table class='matchdisplay'><tr>";echo "<th class='th' colspan='6'>" . $greenclan . "</td>"; }else{echo "<table class='matchdisplay'><tr>";echo "<th class='th' colspan='6'>" . $greenclan . " " . $greenscore . "</td>"; }echo "</tr><tr><th class='th'>Player</th><th class='th'>Score</th><th class='th'>Kills</th><th class='th'>Deaths</th><th class='th'>Caps</th><th class='th'>Attempts</strong></th></tr>";$stats=mysql_query("SELECT * FROM Scorecard WHERE GameID='$matchid' ORDER BY ID LIMIT 0,6");while($row=mysql_fetch_array($stats)){echo "<tr>\n";echo "<td class='tdshow'>" . $row['Player'] . "</td>";echo "<td class='tdshow'>" . $row['Score'] . "</td>";echo "<td class='tdshow'>" . $row['Kills'] . "</td>";echo "<td class='tdshow'>" . $row['Deaths'] . "</td>";echo "<td class='tdshow'>" . $row['Caps'] . "</td>";echo "<td class='tdshow'>" . $row['Attempts'] . "</td>";echo "</tr>\n";}echo "</table>";echo "</td>";echo "<td>";echo "</td>";echo "<td>";if($greenscore==0){echo "<table class='matchdisplay'><tr>";echo "<th class='th' colspan='6'>" . $redclan. "</td>"; }else{echo "<table class='matchdisplay'><tr>";echo "<th class='th' colspan='6'>" . $redclan . " " . $redscore . "</td>"; }echo "</tr><tr><th class='th'>Player</th><th class='th'>Score</th><th class='th'>Kills</th><th class='th'>Deaths</th><th class='th'>Caps</th><th class='th'>Attempts</strong></th></tr>"; $stats=mysql_query("SELECT * FROM Scorecard WHERE GameID='$matchid' ORDER BY ID LIMIT 6,11");while($row=mysql_fetch_array($stats)){echo "<tr>\n";echo "<td class='tdshow'>" . $row['Player'] . "</td>";echo "<td class='tdshow'>" . $row['Score'] . "</td>";echo "<td class='tdshow'>" . $row['Kills'] . "</td>";echo "<td class='tdshow'>" . $row['Deaths'] . "</td>";echo "<td class='tdshow'>" . $row['Caps'] . "</td>";echo "<td class='tdshow'>" . $row['Attempts'] . "</td>";echo "</tr>\n";}echo "</table>";echo "<form id='deletematch' name='deletematch' method='post' action=''>";echo "</td></tr><tr><td class='button' colspan='3'>";echo "<input type='Submit' value='Delete Match' name='Delete'>";echo "</form>";if($_POST['Delete']){mysql_query("DELETE FROM Scorecard WHERE GameID='$matchid'");mysql_query("UPDATE Schedule SET GreenS='0', RedS='0' WHERE GameID='$matchid'");}if($_POST['Delete']==true){ echo "<meta http-equiv=\"refresh\" content=\"0;URL=scheduleedit.php?match=$matchid\">";} echo "</td></tr></table>";?></body></html>

Link to comment
Share on other sites

You won't have to submit twice if that's what you mean. Just change the names of your inputs like I showed you. grnPlayer[], redPlayer[], etc....For the first table use grn... and for the second table use red...Of course you will have to change the script that actually inserts the data into the database to accomodate for the new names. You'll have to do two loops: one for grnPlayer[] and one for redPlayer[] This also means you'll have two insert queries. One for green and one for red.Create a backup of what you have, make your changes, post the code and I'll see if I can help you iron out any issues you might have.

Link to comment
Share on other sites

k i got it done now, seems to insert..now i need that hidden input?

$playerdrop = mysql_query("SELECT * FROM Players WHERE ClanName='".$greenclan."'");if (!$playerdrop)  {  die('Could not connect: ' . mysql_error());  }$playerSelect = "<select class='form' name='grnplayer[]' id='select".$i."'>";$playerSelect.="<option value=''>" . "Player" . "</option>";while($green = mysql_fetch_array( $playerdrop )) {$playerSelect.="<option id='player".$i."' value=".$green['Player'].">".$green['Player']."</option>";}$playerSelect.="</select>";$i=0;do  {  $i++;echo "<tr>\n";echo "<td class='td'>\n";echo $playerSelect;echo "</td>\n";echo "<td class='td'><input class='form' type='text' name='grnscore[]' id='score".$i."' value='' size='3'></td>\n";echo "<td class='td'><input class='form' type='text' name='grnkills[]' id='kills".$i."' value='' size='2'></td>\n";echo "<td class='td'><input class='form' type='text' name='grndeaths[]' id='deaths".$i."' value='' size='4'></td>\n";echo "<td class='td'><input class='form' type='text' name='grncaps[]' id='caps".$i."' value='' size='2'></td>\n";echo "<td class='td'><input class='form' type='text' name='grnattempts[]' id='attempts".$i."' value='' size='6'></td>\n";echo "<td class='td'><input class='form' type='radio' name='grnmvpradio[]' id='mvpradio".$i."' value='1'></td>\n";echo "</tr>\n";  }  while ($i<=5); echo "</table>";echo "</td>";echo "<td>";echo "</td>";echo "<td>";echo "<table class='table'><tr>";echo "<th class='th'>" . $row['Red'] .  " " . Score . "</th>"; echo "<th class='td'>" . "<input type='text' class='form' name='reds' id='reds' value='' size='2'>" . "</td>";echo "<th class='th' colspan='5'>" . "</th>";}echo "</tr><tr><th class='th'>Player</th><th class='th'>Score</th><th class='th'>Kills</th><th class='th'>Deaths</th><th class='th'>Caps</th><th class='th'>Attempts</th><th class='th'>MVP</th></tr>";$playerdrops = mysql_query("SELECT * FROM Players WHERE ClanName='".$redclan."'");if (!$playerdrops)  {  die('Could not connect: ' . mysql_error());  }$playerSelects = "<select class='form' name='redplayer[]' id='select".$i."'>";$playerSelects.="<option value=''>" . "Player" . "</option>";while($red= mysql_fetch_array( $playerdrops )) {$playerSelects.="<option id='player".$i."' value=".$red['Player'].">".$red['Player']."</option>";}$playerSelects.="</select>";$i=0;do  {  $i++;echo "<tr>\n";//echo "<td class='td'><input class='form' type='text' name='player[]' id='player".$i."' value='' size='12'></td>\n";echo "<td class='td'>\n";echo $playerSelects;echo "</td>\n";echo "<td class='td'><input class='form' type='text' name='redscore[]' id='score".$i."' value='' size='3'></td>\n";echo "<td class='td'><input class='form' type='text' name='redkills[]' id='kills".$i."' value='' size='2'></td>\n";echo "<td class='td'><input class='form' type='text' name='reddeaths[]' id='deaths".$i."' value='' size='4'></td>\n";echo "<td class='td'><input class='form' type='text' name='redcaps[]' id='caps".$i."' value='' size='2'></td>\n";echo "<td class='td'><input class='form' type='text' name='redattempts[]' id='attempts".$i."' value='' size='6'></td>\n";echo "<td class='td'><input class='form' type='radio' name='redmvpradio[]' id='mvpradio".$i."' value='1'></td>\n";echo "</tr>\n";  }  while ($i<=5);// while (++$tables <= 2); echo "</table>";echo "</td></tr><tr><td class='button' colspan='3'>";echo "<input type='Submit' value='Add Match' name='Submit'>";echo "</form>";echo "</td></tr>";?><tr><td><?phpif($_POST['Submit']){$index = 0;while (isset($_POST['grnplayer'][$index])) {$grnPlayer=$_POST['grnplayer'][$index];$grnScore=$_POST['grnscore'][$index];$grnKills=$_POST['grnkills'][$index];$grnDeaths=$_POST['grndeaths'][$index];$grnCaps=$_POST['grncaps'][$index];$grnAttempts=$_POST['grnattempts'][$index];$grnMVP=$_POST['grnmvpradio'][$index];$index++;$query="INSERT INTO Scorecard(ID, Player, Score, Kills, Deaths, Caps, Attempts, GameID, MVP)VALUES ('NULL','".$grnPlayer."','".$grnScore."','".$grnKills."','".$grnDeaths."','".$grnCaps."','".$grnAttempts."','".$grnmatchid."','".$grnMVP."')";mysql_query($query) or die ('Error updating database');}}if($_POST['Submit']){$index = 0;while (isset($_POST['redplayer'][$index])) {$redPlayer=$_POST['redplayer'][$index];$redScore=$_POST['redscore'][$index];$redredKills=$_POST['redkills'][$index];$redDeaths=$_POST['reddeaths'][$index];$redCaps=$_POST['redcaps'][$index];$redAttempts=$_POST['redattempts'][$index];$redMVP=$_POST['redmvpradio'][$index];$index++;$query="INSERT INTO Scorecard(ID, Player, Score, Kills, Deaths, Caps, Attempts, GameID, MVP)VALUES ('NULL','".$redPlayer."','".$redScore."','".$redKills."','".$redDeaths."','".$redCaps."','".$redAttempts."','".$redmatchid."','".$redMVP."')";mysql_query($query) or die ('Error updating database');}}

Link to comment
Share on other sites

If i do use this hidden blank and post/query i get the clan name spelled out in 3 cells lol. i've only done it on one side, and only have two names to choose from on the red side. its still entering blank rows, haven't gotten to that yet.

echo "<td class='td'><input class='form' type='text' name='redscore[]' id='score".$i."' value='' size='3'></td>\n";echo "<td class='td'><input class='form' type='text' name='redkills[]' id='kills".$i."' value='' size='2'></td>\n";echo "<td class='td'><input class='form' type='text' name='reddeaths[]' id='deaths".$i."' value='' size='4'></td>\n";echo "<td class='td'><input class='form' type='text' name='redcaps[]' id='caps".$i."' value='' size='2'></td>\n";echo "<td class='td'><input class='form' type='text' name='redattempts[]' id='attempts".$i."' value='' size='6'></td>\n";echo "<td class='td'><input class='form' type='radio' name='redmvpradio[]' id='mvpradio".$i."' value='1'></td>\n";echo "<input type='hidden' name='redclan' id='redclan".$i."' value='".$redclan."' />";echo "</tr>\n";  }  while ($i<=5);

$redClan=$_POST['redclan'][$index];$index++;$query="INSERT INTO Scorecard(ID, Player, Score, Kills, Deaths, Caps, Attempts, GameID, MVP, Clan)VALUES ('NULL','".$redPlayer."','".$redScore."','".$redKills."','".$redDeaths."','".$redCaps."','".$redAttempts."','".$matchid."','".$redMVP."','".$redClan."')";mysql_query($query) or die ('Error updating database');

2mn25nt.jpg

Link to comment
Share on other sites

It sounds like the full name is in $_POST['redclan'], but you can always print that to find out. Or, better yet, print all of post:print_r($_POST);Then you can find out exactly what's there.
tried putting the print inside the while loop of the post and got nothing. so i'm not sure where its supposed to go :3
Link to comment
Share on other sites

You can put print_r anywhere, $_POST is global. Just make sure it's somewhere where you'll see the output. I'm not sure you would want to use print_r($_POST) in a loop though, it would keep printing the same thing. If in doubt, put it at the top of the script. It won't print nothing though, at a minimum it will print this:Array ()

Link to comment
Share on other sites

Array ( [greens] => 3 [grnplayer] => Array ( [0] => Greysoul [1] => Dekard [2] => Cartman [3] => SadLittleMan [4] => Phrozen [5] => Static ) [grnscore] => Array ( [0] => 1 [1] => 1 [2] => 2 [3] => 2 [4] => 2 [5] => 8 ) [grnkills] => Array ( [0] => 1 [1] => 1 [2] => 2 [3] => 2 [4] => 2 [5] => 2 ) [grndeaths] => Array ( [0] => 1 [1] => 1 [2] => 2 [3] => 2 [4] => 2 [5] => 67 ) [grncaps] => Array ( [0] => 1 [1] => 1 [2] => 2 [3] => 2 [4] => 4 [5] => 6 ) [grnattempts] => Array ( [0] => 1 [1] => 1 [2] => 2 [3] => 2 [4] => 5 [5] => 5 ) [grnclan] => NoF [reds] => 1 [redplayer] => Array ( [0] => Ghost [1] => Forsaken [2] => [3] => [4] => [5] => ) [redscore] => Array ( [0] => [1] => [2] => [3] => [4] => [5] => ) [redkills] => Array ( [0] => [1] => [2] => [3] => [4] => [5] => ) [reddeaths] => Array ( [0] => [1] => [2] => [3] => [4] => [5] => ) [redcaps] => Array ( [0] => [1] => [2] => [3] => [4] => [5] => ) [redattempts] => Array ( [0] => [1] => [2] => [3] => [4] => [5] => ) [redclan] => SiC [submit] => Add Match )

Link to comment
Share on other sites

View the source of the HTML page so you can get the formatted version of that, it's easier to read. It looks like it's just $_POST['redclan']. You should be able to print that to verify that it contains the name.

Link to comment
Share on other sites

not really sure what i'm lookin for here lolArray( [greens] => 3 [grnplayer] => Array ( [0] => Greysoul [1] => Dekard [2] => Cartman [3] => SadLittleMan [4] => Phrozen [5] => Static ) [grnscore] => Array ( [0] => 1 [1] => 1 [2] => 2 [3] => 2 [4] => 2 [5] => 8 ) [grnkills] => Array ( [0] => 1 [1] => 1 [2] => 2 [3] => 2 [4] => 2 [5] => 2 ) [grndeaths] => Array ( [0] => 1 [1] => 1 [2] => 2 [3] => 2 [4] => 2 [5] => 67 ) [grncaps] => Array ( [0] => 1 [1] => 1 [2] => 2 [3] => 2 [4] => 4 [5] => 6 ) [grnattempts] => Array ( [0] => 1 [1] => 1 [2] => 2 [3] => 2 [4] => 5 [5] => 5 ) [grnclan] => NoF [reds] => 1 [redplayer] => Array ( [0] => Ghost [1] => Forsaken [2] => [3] => [4] => [5] => ) [redscore] => Array ( [0] => [1] => [2] => [3] => [4] => [5] => ) [redkills] => Array ( [0] => [1] => [2] => [3] => [4] => [5] => ) [reddeaths] => Array ( [0] => [1] => [2] => [3] => [4] => [5] => ) [redcaps] => Array ( [0] => [1] => [2] => [3] => [4] => [5] => ) [redattempts] => Array ( [0] => [1] => [2] => [3] => [4] => [5] => ) [redclan] => SiC [submit] => Add Match)

Link to comment
Share on other sites

If i do use this hidden blank and post/query i get the clan name spelled out in 3 cells lol. i've only done it on one side, and only have two names to choose from on the red side. its still entering blank rows, haven't gotten to that yet.
echo "<td class='td'><input class='form' type='text' name='redscore[]' id='score".$i."' value='' size='3'></td>\n";echo "<td class='td'><input class='form' type='text' name='redkills[]' id='kills".$i."' value='' size='2'></td>\n";echo "<td class='td'><input class='form' type='text' name='reddeaths[]' id='deaths".$i."' value='' size='4'></td>\n";echo "<td class='td'><input class='form' type='text' name='redcaps[]' id='caps".$i."' value='' size='2'></td>\n";echo "<td class='td'><input class='form' type='text' name='redattempts[]' id='attempts".$i."' value='' size='6'></td>\n";echo "<td class='td'><input class='form' type='radio' name='redmvpradio[]' id='mvpradio".$i."' value='1'></td>\n";echo "<input type='hidden' name='redclan' id='redclan".$i."' value='".$redclan."' />";echo "</tr>\n";  }  while ($i<=5);

You should move that hidden input outside the table. I'd put it just before your opening <table> tag. You only need to print it once per clan anyway so it doesn't need to be in the loop.
not really sure what i'm lookin for here lol
What JSG is saying is that the following line....
$redClan=$_POST['redclan'][$index];

....Should just be...

$redClan=$_POST['redclan'];

You don't need to have the [$index] since the clan name is not an array.You can see that by looking at this line in the print_r output you posted above:[redclan] => SiC...as opposed to, say, this segment:[grnscore] => Array([0] => 1[1] => 1[2] => 2[3] => 2[4] => 2[5] => 8)

Link to comment
Share on other sites

You should move that hidden input outside the table. I'd put it just before your opening <table> tag. You only need to print it once per clan anyway so it doesn't need to be in the loop.What JSG is saying is that the following line....
$redClan=$_POST['redclan'][$index];

....Should just be...

$redClan=$_POST['redclan'];

You don't need to have the [$index] since the clan name is not an array.You can see that by looking at this line in the print_r output you posted above:[redclan] => SiC...as opposed to, say, this segment:[grnscore] => Array([0] => 1[1] => 1[2] => 2[3] => 2[4] => 2[5] => 8)

so yeah, why array it when the value isn't going to change and its going to repeat..thats the purpose of the array in this case, to avoid that right? lol it works now, i just wish these things came to me as common sense in the beginning.
Link to comment
Share on other sites

it works now, i just wish these things came to me as common sense in the beginning.
5 pages and 90-some posts later...:)I'm glad to hear you got it going, and glad to help. (Don't worry about the 90 posts, I was just being a smart-*** :) )
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.


×
×
  • Create New...