Adam1239 Posted August 10, 2007 Share Posted August 10, 2007 I need help with foreach none checked checkbox as value, can you even do that. I tryed the !isset(); function but i'm not sure it would work because the none checked box would not of run with the $_POST ( i think ) this is an example table of what i'm looking for help with: ({num}) = the value [] = the checkbox. (1)(2)(3)(4) [] [] [] [] the person checks the one(s) they wish to keep and the none checked ones get swaped for diffrant values. I'm not quite sure if it is possible, but i will ask anyway to see if anyone as a solution.. Thanks, Adam. Quote Link to comment https://forums.phpfreaks.com/topic/64278-for-each-none-checked-checkbox/ Share on other sites More sharing options...
corillo181 Posted August 10, 2007 Share Posted August 10, 2007 you can do it with the short if tag run a foreach and then use their value as $newValue=(empty($value))?'New Value':'Old Value'; Quote Link to comment https://forums.phpfreaks.com/topic/64278-for-each-none-checked-checkbox/#findComment-320450 Share on other sites More sharing options...
Fadion Posted August 10, 2007 Share Posted August 10, 2007 U could post your code to see what isnt going wrong. I can only tell how i manage checkboxes: If they will be dynamically created, i place them in a while loop, to fill their values with data from ex. Database. I make their names like 'chkBox1', 'chkBox2' etc. To get those values u can run a for loop and check with isset() or array_key_exists() to determine which of them is checked. for($i=0; $i<count($arrChkBoxes); $i++){ if(isset($_POST['chkBox' . $i])){ //do something } else{ //do something else } } EDIT: $_POST return only the value of the checked checkboxes Quote Link to comment https://forums.phpfreaks.com/topic/64278-for-each-none-checked-checkbox/#findComment-320456 Share on other sites More sharing options...
Adam1239 Posted August 10, 2007 Author Share Posted August 10, 2007 U could post your code to see what isnt going wrong. I can only tell how i manage checkboxes: If they will be dynamically created, i place them in a while loop, to fill their values with data from ex. Database. I make their names like 'chkBox1', 'chkBox2' etc. To get those values u can run a for loop and check with isset() or array_key_exists() to determine which of them is checked. for($i=0; $i<count($arrChkBoxes); $i++){ if(isset($_POST['chkBox' . $i])){ //do something } else{ //do something else } } EDIT: $_POST return only the value of the checked checkboxes I apologise for not explaining it right, this is how it goes. the swap is a $_POST['swap']; which returns the value of what they want to swap ( in this case the checkboxs ) this code works but you have to check the box's you wish to swap insted of checking the box's you wish to keep, there is no big problem but if there is a way how to make them check the box's they want to keep it would make it alittle better. and the table game as the drew which is where the values come in (1)(2) etc and they are displayed in the form part. it is something like this 8-4-3-2-5 in the row draw. the $_POST['chan'] value echos the $switch $switch = 1; if($_POST['chan'] == "1") { $switch = 2; /// Switch makes it update $_POST['clan']; to 2 so it goes onto the next round. if(isset($swap)) { foreach ($swap as $value) { $query = "SELECT * FROM game WHERE username='$username'"; $result = mysql_query($query); $get_game = mysql_fetch_object($result); $c = explode("-",$get_game->draw); $num = rand(1,6); switch($value){ case 0: $change = "$num-$c[1]-$c[2]-$c[3]-$c[4]"; break; case 1: $change = "$c[0]-$num-$c[2]-$c[3]-$c[4]"; break; case 2: $change = "$c[0]-$c[1]-$num-$c[3]-$c[4]"; break; case 3: $change = "$c[0]-$c[1]-$c[2]-$num-$c[4]"; break; case 4: $change = "$c[0]-$c[1]-$c[2]-$c[3]-$num"; break; } $go = "UPDATE game SET draw='$change' WHERE username='$username'"; $go_result = mysql_query($go); } } } Quote Link to comment https://forums.phpfreaks.com/topic/64278-for-each-none-checked-checkbox/#findComment-320470 Share on other sites More sharing options...
Adam1239 Posted August 10, 2007 Author Share Posted August 10, 2007 Also they get 3 chance's to swap to make the best hand the final result is called when the $switch reachs 3 then it calls afew functions to check there final hand values Quote Link to comment https://forums.phpfreaks.com/topic/64278-for-each-none-checked-checkbox/#findComment-320473 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.