Jump to content

Easier Way To Make Almost 80 Insert Boxes


Recommended Posts

  • Replies 95
  • Created
  • Last Reply

Top Posters In This Topic

Ok this is the loop I was referring to:

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');}

Just put a conditional around your query that tests, for example, if the player value is blank.if ($Player != '') {//...Do the query}That way if the player input box is left blank it won't insert a row.Did you get the clans thing figured out?

Edited by jkloth
Link to post
Share on other sites

i decided to go the extra mile of not making the players name typable..because if they type it wrong it throws everything out of wack. i'm trying to make it a drop down. trying to figure out why the drop down isn't populating. this is a while loop inside of a do loop.

// variables from up above$greenclan = $row['Green'];$redclan = $row['Red'];$playerdrop = mysql_query("SELECT * FROM Players WHERE ClanName= '".$greenclan."'");$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'>" . "<select name='select' id='select'>";while($green = mysql_fetch_array( $playerdrop )) {echo "<option value=".$green['Player'].">".$green['Player']."</option>";echo "</select>";}

Edited by Greysoul
Link to post
Share on other sites
still working on clans. for the blank insert..that won't make it where even if one blank is empty..none will insert?
If the player name is empty (you don't type anything in the box) nothing for that table row will be inserted.As for the drop down, I just looked back at you first post with the screenshot and I noticed the checkboxes. What are those for? You could create you table with all of the players names already there and just use the checkbox to determine if their scores should be inserted. If it's checked insert the data otherwise don't.Unless of course the checkboxes are already used for something else. Edited by jkloth
Link to post
Share on other sites

Those were intended for, if checked, insert that data row. Ones left unchecked would insert no row. I figured I could do the same with blanks without check boxes so I got rid of them. Player names aren't known till game time and rosters reach over into the 20's so that would be a monster list lol.

Link to post
Share on other sites

You don't get any names in the drop down? Do you get any errors? Do a print_r($green) inside the while loop to see what the array holds.EDIT:I just noticed that you are closing the select inside the while loop. Move this line...echo "</select>";...out of the while loop and see what happens.

Edited by jkloth
Link to post
Share on other sites

yeah i fixed that already and now it shows all player names in the DB. i had my query set without a where statement to make sure i was doing it right. now i have to fix my where statement because when i add it, it takes away all names and leaves an empty drop down. here's my entire new code again..very long ;x

<!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.'");$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'>" . "<select name='select' id='select'>";while($green = mysql_fetch_array( $playerdrop )) {echo "<option value=".$green['Player'].">".$green['Player']."</option>";}echo "</select>";echo "</td>";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>";$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'><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 post
Share on other sites

You've got some extra dots in your query string:

$playerdrop = mysql_query("SELECT * FROM Players WHERE ClanName='.$greenclan.'");

It should be:

$playerdrop = mysql_query("SELECT * FROM Players WHERE ClanName='".$greenclan."'");

or...

$playerdrop = mysql_query("SELECT * FROM Players WHERE ClanName='$greenclan'");

Link to post
Share on other sites

Change the query string back to this:$playerdrop = mysql_query("SELECT * FROM Players WHERE ClanName='".$greenclan."'");Then after that line echo mysql_error() to see if there was an error with the query.

Link to post
Share on other sites
there's only player field thats filling out with names..i assumed it was because the .$i. wasn't on that form id so i added it to no avail
there's only...one?...player field populating. Post the loop code. I don't need all of your code just the loop(s) for this portion (but make sure you have the entire loop :) )
Link to post
Share on other sites
$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'>" . "<select name='player[]' id='select".$i."'>";while($green = mysql_fetch_array( $playerdrop )) {echo "<option id='player".$i."' value=".$green['Player'].">".$green['Player']."</option>";}echo "</select>";echo "</td>";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);

Link to post
Share on other sites

OK I think I know what's going on. The record pointer in your results is moving to the next record every time you call mysql_fetch_array, so when the loop is done the pointer is at the end of the result set. I don't know how to reset that pointer but I think I might have a solution. It is probably not the best or most elegant but I think it will work.Just move the while loop out of the do loop and create a string variable to use in the do loop. Something like this:

$playerSelect = "<select name='player[]' id='select".$i."'>";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'><input class='form' type='text' name='player[]' id='player".$i."' value='' size='12'></td>\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);

You'll have to recreate the $playerSelect variable anytime the list of players is going to change, though, which is why I say it's probably not the greatest solution.

Link to post
Share on other sites
the players clan into the scorecard, so that i can view them later by clan name. remember i have it now where it lists the first 6 of a game id for green, and the last 6 for red.
Don't you have the clan name stored for the players in the player table? Or do players not have a specific clan assigned to them?
Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...

×
×
  • Create New...