Jump to content

[SOLVED] foreach acting gay


Demonic

Recommended Posts

				foreach($_POST['valid'] as $valid){

					if($valid){
						echo $valid." true<br />";
					}else{
						echo $valid." false<br />";
					}

				}

 

Alright when I check a field it echos each one true but if its not checked how come its not echoing false?

 

Does this happen so often?

 

(echos 4 inputs, I check 2 only 2 say true and the other 2 won't echo false).

 

 

Link to comment
Share on other sites

No that doesn't help:

 

			$array = array();

				foreach($_POST['valid'] as $valid){

				/*	if($valid){
						echo $valid." true<br />";
					}else{
						echo $valid." false<br />";
					}*/
				($valid) ? $array[$valid] = "y" : $array[$valid] = "n";

				}
				print_r($array);

Array ( [1] => y [3] => y )

 

Input 1 and input 3 checked.^

Link to comment
Share on other sites

Alright this what I did:

 

function Gtemplates(){

	$skin = mysql_query("SELECT * FROM user_groups");
	while($sk = mysql_fetch_array($skin)){
		$skinz .=
		'
			<tr>
				<td class="main_cat_box" width="30%" align="center">'.$sk[name].'</td>
				<td class="main_cat_box" width="70%" align="center"><input type="checkbox" onClick="if(this.checked==checked){this.value = this.value.split(\'|\')[0]+\'|t\';}else{this.value = this.value.split(\'|\')[0]+\'|f\';}" name="valid[]" value="'.$sk[id].'|f" /></td>
			</tr>
		';
	}
		return $skinz;
}

 

So it has 4 inputs right?

 

so it switches value BUT I HAVE THE SAME ERROR O_O

 

 

 

 

			$array = array();
				foreach($_POST['valid'] as $valid){
				$valid = explode("|",$valid);
				($valid[1] == "t") ? $array[$valid[0]] = "y" : $array[$valid[0]] = "n";
				}
				print_r($array);

 

Array ( [1] => y [4] => y )

 

input 1 and 4 was checked -_-.

Link to comment
Share on other sites

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.