Jump to content

[SOLVED] CheckBox problems


MiCR0

Recommended Posts

I am getting this odd thing happen after i post it again after, Can anyone see why?

 

I select using say

NAME=lines & UID=4 & V=on

NAME=lines & UID=14 & V=on

NAME=lines & UID=21 & V=on

4/14/21/

All is correct however If I try posting again after an update ALL are selected and V = there uid very odd anyone see where I gone wrong?

 

function Checkbox3($DISPLAY_TEXT,$NAME,$CHECKED,$REQUIRED,$DISPLAY_END_TEXT,$TABLE_NAME){

if ($CHECKED == TRUE)
	{
		if ($REQUIRED == TRUE)
			{
			$sql = 'SELECT * FROM classifieds__data_grid WHERE TABLE_NAME = '.$TABLE_NAME;
			$result = mysql_query($sql);
			$results = mysql_fetch_object($result);
			$NAME = data_safe($results->NAME);

			$THERE = FALSE;
			$sql = 'SELECT * FROM data_array__'.$TABLE_NAME;
			$resultZ = mysql_query($sql);
			$SELECTED = NULL;
			while ($row = mysql_fetch_object($resultZ))
				{
					//print_r($row);
					foreach ($_POST as $k => $v) 
						{
						$data = explode("/", $k);
						$UID = (int) intval($data[1]);
						if (data_safe($NAME) == $data[0] && $UID == $row->UID)
							{
							ECHO 'NAME='.$NAME. ' & UID='.$UID.' & V='.$v.'<BR/>';
							$SELECTED .= $UID.'/';
							}
						}
				}

			print_r($SELECTED);
			if ($SELECTED == NULL)
				{
				$ERROR = ' <span style="color:#FF0000"><strong>Required An Selection Of One!</strong></span> ';
				}

			}
	}



$sql = 'SELECT * FROM data_array__'.$TABLE_NAME;
$result = mysql_query($sql);
$count = 0;
$display .= '<span style="font-weight: bold;">'.$DISPLAY_TEXT.'</span><br/>';
$display .='<table cellspacing="0" cellpadding="0" border="0">';
	while ($row = mysql_fetch_object($result))
		{
			$is_selected = FALSE;
			$count++;
			if ($count == 1)
				{
				$display .='<tr>';

				}	

			$selected_array = explode("/", $SELECTED);	

			foreach ($selected_array AS $selected)
				{
				if ($selected == $row->UID)
					{

					$is_selected = TRUE;
					}
				}
			if ($is_selected == TRUE)
				{
				$display .= '<td><label><input name="'.$NAME.'/'.$row->UID.'" type="checkbox" value=""  checked="checked" />
							'.$row->CATEGORIES.'</label>'.$DISPLAY_END_TEXT.'</td>';
				}else
					{
					$display .= '<td><label><input name="'.$NAME.'/'.$row->UID.'" type="checkbox" value=""/>
							'.$row->CATEGORIES.'</label>'.$DISPLAY_END_TEXT.'</td>';
					}
			if ($count == 3)
				{
				$display .= '</tr>';
				$count = 0;
				}
		}

		$display .= '<input name="'.$NAME.'" type="hidden" id="'.$NAME.'" value="'.$NAME.'" /> </table> '.$ERROR.'<br/>';


return $display;
}

Link to comment
https://forums.phpfreaks.com/topic/159678-solved-checkbox-problems/
Share on other sites

Like I Select

 

15

27

 

Hit Enter all is fine it posted back the correct selections however.

If i hit Enter Again I get all of the following values which I have not selected.

 

15

16

17

18

19

20

21

22

23

24

25

26

27

 

Its all of the boxes between the values I have selected are then selected and I can not see how this is doing this can anyone? As this is really doing my head in now.

 

Thanks in Advance.

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.