Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/64278-for-each-none-checked-checkbox/
Share on other sites

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.