OutOfInk Posted April 6, 2014 Share Posted April 6, 2014 I have multiple checkboxes which im submitting data from and need to retrieve that data. I need to be able to get closewin[$i] and winner[$i] into the same foreach() statement so that it stops defaulting to the first 0 to 8 options; my code is below; I have placed $o++ in there to make all closewin[$i] options different <?php $fuck = $globalRound[0] - 1; // On round 3 if (isset($_POST['subclose'])){ foreach ($_POST['winner'] as $index => $value){ $a = $_POST['closewin']; $b = $value; $q = mysql_fetch_row(mysql_query("SELECT FROM WHERE `` = '$b[$i]'")); if ($a[$i] = $q[0]){ $d = $q[0]; $e = $q[1]; }else{ $d = $q[1]; $e = $q[0]; } mysql_query("UPDATE "); echo "You have selected $a[$i] as the winner!<br />"; echo "---------------------------<br />"; } echo "<b>You have closed Round $fuck, leaderboard is now updated, ppc credited for winners!</b><br />"; } ?> <form action="/p.php" method="post" name="closeg"> <table border='1' cellpadding='2' cellspacing='0' bordercolor='#000000' class='sub2' width="620"> <tr class="innertable"><td align="center" colspan="2"><b>Close Round / Update Leader Board / Credit PPC wins</b></td></tr> <?php $i = 0; $o = 9; $selectclose = mysql_query("SELECT `id` , `Home` , `Away` FROM `` WHERE `Round` = '$fuck'"); while ($closeselect = mysql_fetch_row($selectclose)){ echo " <tr class=innertable> <td> <input type='hidden' name='winner[$i]' value='$closeselect[0]'> <input type='checkbox' class='input' name='closewin[$i]' value='$closeselect[1]'>$closeselect[1] </td><td> <input type='checkbox' class='input' name='closewin[$o]' value='$closeselect[2]'>$closeselect[2]</td> </tr>"; $i++; $o++; } ?> <tr><td align="right" colspan="2"><input type="submit" name="subclose" class="input" value="Close Round" /></td></tr> </table> </form> The html form appears like the following; Close Round / Update Leader Board / Credit PPC wins Pleae double check winners before submitting to close the round as once entered, to undo would be impossible. [checkbox] Hawthorn | [checkbox] Fremantle [checkbox]Western Bulldogs | [checkbox]Richmond [checkbox]Adelaide | [checkbox]Sydney [checkbox]Gold Coast | [checkbox]Brisbane Lions [checkbox]Collingwood | [checkbox]Geelong [checkbox]West Coast | [checkbox]St Kilda [checkbox]GWS Giants | [checkbox]Melbourne [checkbox]North Melbourne | [checkbox]Port Adelaide [checkbox]Essendon | [checkbox] Carlton and when submitted with all the right hand side 9 to 17 checkboxes selected it defaults to the left options; You have selected Hawthorn as the winner! --------------------------- You have selected Western Bulldogs as the winner! --------------------------- You have selected Adelaide as the winner! --------------------------- You have selected Gold Coast as the winner! --------------------------- You have selected Collingwood as the winner! --------------------------- You have selected West Coast as the winner! --------------------------- You have selected GWS Giants as the winner! --------------------------- You have selected North Melbourne as the winner! --------------------------- You have selected Essendon as the winner! Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted April 6, 2014 Share Posted April 6, 2014 (edited) You need to give the checkboxes the same index, not separate ones ($i and $o). I'd setup the index to be the id field returned by your query Also you are best of using radio buttons instead of checkboxes, as only one team can be selected to be the winner for each match not both (unless you are allowing for draws?, in which case you'll want to have a third radio button for that) So I'd setup the while loop as while ($closeselect = mysql_fetch_row($selectclose)){ echo " <tr class=innertable> <td> <input type='radio' class='input' name='closewin[$closeselect[0]]' value='$closeselect[1]'>$closeselect[1] </td><td> <input type='radio' class='input' name='closewin[$closeselect[0]]' value='$closeselect[2]'>$closeselect[2]</td> </tr>"; } Now your foreach loop should display the chosen team correctly. Edited April 6, 2014 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
QuickOldCar Posted April 6, 2014 Share Posted April 6, 2014 How about not using curses in your code here. Quote Link to comment Share on other sites More sharing options...
OutOfInk Posted April 7, 2014 Author Share Posted April 7, 2014 Thanks Ch0cu3r, that helped a lot, the only thing im still having trouble with is carrying the ID which i need to relate to the table row for each of those games. $closeselect[0] is important to be carried as that indexs the specific row that $closeselect[1], $closeselect[2] or Draw relate too. At the moment it now gathers the correct option with the radio checked for any of the options but how can i grab that $closeselect[0] Quote Link to comment Share on other sites More sharing options...
OutOfInk Posted April 7, 2014 Author Share Posted April 7, 2014 QuickOldCar how about posting something constructive and useful in a php help forum instead of wasting a post being a forum nazi. Quote Link to comment Share on other sites More sharing options...
QuickOldCar Posted April 7, 2014 Share Posted April 7, 2014 I have 1,573 posts here that are only constructive, you are the only one I have ever seen in all my years here that used profanity in code surely is a TOS rule here for that, and most likely for name calling Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted April 7, 2014 Share Posted April 7, 2014 You'd loop through the $_POST['closewin'] array. The match id will be the key for that array // key => value foreach ($_POST['closewin'] as $match_id => $winning_team) { echo '<p>You have chosen the winning team to be <b>' . $winning_team . '</b> for match id <b>#' . $match_id . '</b></p>'; } Quote Link to comment 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.