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
https://forums.phpfreaks.com/topic/46158-solved-foreach-acting-gay/
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.^

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 -_-.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.