Greysoul Posted March 4, 2010 Author Share Posted March 4, 2010 by the way, i also didn't understand about the empty rows being inserted. you lost me on that one. and yeah it will be much easier if i can calculate it all in php..it lessons my inserts and updates quite a bit lol. Link to comment Share on other sites More sharing options...
ShadowMage Posted March 4, 2010 Share Posted March 4, 2010 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? Link to comment Share on other sites More sharing options...
Greysoul Posted March 4, 2010 Author Share Posted March 4, 2010 still working on clans. for the blank insert..that won't make it where even if one blank is empty..none will insert? Link to comment Share on other sites More sharing options...
Greysoul Posted March 4, 2010 Author Share Posted March 4, 2010 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>";} Link to comment Share on other sites More sharing options...
ShadowMage Posted March 4, 2010 Share Posted March 4, 2010 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. Link to comment Share on other sites More sharing options...
Greysoul Posted March 4, 2010 Author Share Posted March 4, 2010 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 comment Share on other sites More sharing options...
Greysoul Posted March 4, 2010 Author Share Posted March 4, 2010 I'm using the same concept without checkboxes and drop down lists to choose the names from teams. Can't get it to populate the names for some reason though. I posted the code for that in a recent post Link to comment Share on other sites More sharing options...
ShadowMage Posted March 4, 2010 Share Posted March 4, 2010 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. Link to comment Share on other sites More sharing options...
Greysoul Posted March 4, 2010 Author Share Posted March 4, 2010 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 comment Share on other sites More sharing options...
ShadowMage Posted March 4, 2010 Share Posted March 4, 2010 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 comment Share on other sites More sharing options...
Greysoul Posted March 4, 2010 Author Share Posted March 4, 2010 yeah i tried every variation and it doesn't work..is there a problem with how the variable is defined? seems to work fine down below where i display the clan name for the stats output. Link to comment Share on other sites More sharing options...
Greysoul Posted March 4, 2010 Author Share Posted March 4, 2010 down at the bottom where stats are displayed if they exist, that KoD and RS are there by using the $greenclan $redclan..so they must work? Link to comment Share on other sites More sharing options...
ShadowMage Posted March 4, 2010 Share Posted March 4, 2010 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 comment Share on other sites More sharing options...
Greysoul Posted March 4, 2010 Author Share Posted March 4, 2010 like this ? $playerdrop = mysql_query("SELECT * FROM Players WHERE ClanName='".$greenclan."'");if (!$playerdrop) { die('Could not connect: ' . mysql_error()); }if i do that, it just shows like the pic i gave Link to comment Share on other sites More sharing options...
Greysoul Posted March 4, 2010 Author Share Posted March 4, 2010 found the problem, i didn't have any players added in that clan...*SLAPS HIMSELF*. atleast i'm getting the hang of how all this works lol. Link to comment Share on other sites More sharing options...
ShadowMage Posted March 4, 2010 Share Posted March 4, 2010 found the problem, i didn't have any players added in that clan...*SLAPS HIMSELF*lol I hate it when I do something like that! Link to comment Share on other sites More sharing options...
Greysoul Posted March 4, 2010 Author Share Posted March 4, 2010 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 Link to comment Share on other sites More sharing options...
ShadowMage Posted March 4, 2010 Share Posted March 4, 2010 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 availthere'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 comment Share on other sites More sharing options...
Greysoul Posted March 4, 2010 Author Share Posted March 4, 2010 $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 comment Share on other sites More sharing options...
ShadowMage Posted March 4, 2010 Share Posted March 4, 2010 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 comment Share on other sites More sharing options...
Greysoul Posted March 4, 2010 Author Share Posted March 4, 2010 genius kind sir, genius Link to comment Share on other sites More sharing options...
Greysoul Posted March 4, 2010 Author Share Posted March 4, 2010 i guess the only thing thats not really fixed is i still haven't figured out how to make it input the clan name...god lol. i tried making different $_POST for redplayer and greenplayer to insert into clan twice...but that didn't work too well. Link to comment Share on other sites More sharing options...
ShadowMage Posted March 4, 2010 Share Posted March 4, 2010 Input the clan name where? Link to comment Share on other sites More sharing options...
Greysoul Posted March 4, 2010 Author Share Posted March 4, 2010 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. Link to comment Share on other sites More sharing options...
ShadowMage Posted March 4, 2010 Share Posted March 4, 2010 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 comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.