gsaldutti Posted September 20, 2008 Share Posted September 20, 2008 I have a football pool where players pick FOUR teams to win each week, and the only rule is that they can't use the same team more than THREE times. So in my code, I have an basic array for all 32 teams.. $teamsArray = array( 'Philadelphia Eagles', 'Dallas Cowboys', 'New York Giants', 'Washingtong Redskins', 'Detroit Lions', 'Minnestoata Vikings', 'Green Bay Packers', 'Chicago Bears', 'Tampa Bay Buccs', 'New Orleans Saints', 'Carolina Panthers', 'Atlanta Falcons', 'Seattle Seahawks', 'San Francisco 49ers', 'St. Louis Rams', 'Arizona Cardinals', 'New York Jets', 'Miami Dolphins', 'Buffalo Bills', 'New England Patriots', 'Baltimore Ravens', 'Cincinnati Bengals', 'Pittsburgh Steelers', 'Cleveland Browns', 'Houston Texans', 'Tennessee Titans', 'Jacksonville Jaguars', 'Indianapolis Colts', 'Denver Broncos', 'Kansas City Chiefs', 'Oakland Raiders', 'San Diego Chargers', 'BYE'); Next I have a MySQL query to find out how many times teams have been used (see code below). Then it produces a little HTML box listing out each team that user has picked and how many times they were used. Works fine. Then right after that code, I have the submission form (with four DropDown lists, each showing all 32 teams). But that first listing of teams and the # of times used probably woudn't even be necessary AT ALL if I could just write some PHP that would look to the DropDown lists (they are just HTML SELECT lists with 32 OPTIONS....actually 33 because players can choose a BYE) and know specifically which teams in the list of 32 have been used THREE times. Ideally, it would just look to the "class" and change it from "teamdropdown" to "teamdropdownNO" and then in my CSS I could make the "teamdropdownNO" class have "text-decoration: strike-trough" (so the teams used 3 times had a line through them) or maybe just us "Display: none" so the teams used three times didn't even show up at all. But I cannot figure out how to change strings in the DropDown lists for just certain teams (i.e. the teams used three times) in the FOR LOOP. I've tried "str_replace" but cannot get it to work. I'm not asking anyone to write the code for me, but if someone can at least point me in the right direction of how this can/shoud be done, I would REALLY appreciate it. <form action="submit.php" method="post" /> <table id="submitform"> <?php echo "<div id='teamsused'>"; echo "<p class='reminder'>Remember, you can only use each team THREE times, maximum!</p>"; echo "<p class='teamsusedheader'>List of Teams Used (# of times used so far is in parentheses):</p>"; $query = "SELECT picks.teamid, COUNT(*) AS count, teams.teamname FROM picks, teams WHERE userid = '{$_SESSION['userid']}' AND picks.teamid = teams.teamid GROUP BY teamid ORDER BY count DESC"; $getTeams = mysql_query($query, $connection); if (!$getTeams) { die("Database query failed: " . mysql_error()); } while ($results = mysql_fetch_array($getTeams)) { if ($results['count'] > 3) { echo "<span class='four'>" . $results['teamname'] . " (" . $results['count'] . ") ***** You used this team TOO MANY TIMES.<br/> CONTACT GARY TO DISCUSS!!!!</span><br/>"; } elseif ($results['count'] == 3) { echo "<span class='three'>" . $results['teamname'] . " (" . $results['count'] . ") You CANNOT pick this team anymore</span><br/>"; } elseif ($results['count'] == 2) { echo "<span class='two'>" . $results['teamname'] . " (" . $results['count'] . ") You can only pick this team ONCE MORE</span><br/>"; } else { echo "<span class='one'>" . $results['teamname'] . " (" . $results['count'] . ")</span><br/>"; } } echo "</div>"; //Begin code for Pick Submission form for($x=1; $x<=4; $x++){ echo "\n<tr><td>Pick ".$x.':</td>'; echo "\n<td><select name=\"pickArray[]\"/>"; echo "\n<option class='' value=''></option>"; for($y=0; $y<count($teamsArray); $y++){ $teamID = $y+1; $teamdropdown = "\n<option class='teamdropdown' value='{$teamID}'>{$teamsArray[$y]}</option>"; echo $teamdropdown; } echo "\n</select>"; echo "\n</td>"; echo "</tr>"; } echo "\n<tr><td>Week:</td>"; echo "\n<td><select name=\"week\"/>"; echo "\n<option class='' value=''></option>"; for($x=2; $x<=17; $x++){ echo "\n<option class='' value='$x'>$x</option>"; } echo "\n</select>"; echo "\n".'<input type="submit" name="submit" value="Submit Picks" class="submitpicksbutton" /></td>'; echo '</tr></table></form>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/125081-manipulating-certain-html-select-list-strings-but-not-others/ Share on other sites More sharing options...
dropfaith Posted September 20, 2008 Share Posted September 20, 2008 i dont think you can edit some selections of a select box without effecting the others what i would do is just make an extra column in mysql named disabled and if the team was chosen 3 times have that update to True then only display the results from mysql that werent true using the WHERE statement Quote Link to comment https://forums.phpfreaks.com/topic/125081-manipulating-certain-html-select-list-strings-but-not-others/#findComment-646430 Share on other sites More sharing options...
gsaldutti Posted September 20, 2008 Author Share Posted September 20, 2008 I don't think that would work since there are many different people in the pool. So the Cowboys might be used three times for BOB, but may only be used once for MIKE. So I don't it would work to mark the Cowboys as disabled because MIKE still needs to be able to pick them. Then again, I might be misunderstanding what you're saying Quote Link to comment https://forums.phpfreaks.com/topic/125081-manipulating-certain-html-select-list-strings-but-not-others/#findComment-646434 Share on other sites More sharing options...
dropfaith Posted September 20, 2008 Share Posted September 20, 2008 nah you might be right how are your tables formated? Quote Link to comment https://forums.phpfreaks.com/topic/125081-manipulating-certain-html-select-list-strings-but-not-others/#findComment-646447 Share on other sites More sharing options...
gsaldutti Posted September 20, 2008 Author Share Posted September 20, 2008 Just three tables in the whole database... USERS (userid, username, password, firstname, lastname) TEAMS (teamid, teamname) PICKS (userid, teamid, week, result) That's it. Quote Link to comment https://forums.phpfreaks.com/topic/125081-manipulating-certain-html-select-list-strings-but-not-others/#findComment-646553 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.