Link to home
Start Free TrialLog in
Avatar of JohnMac328
JohnMac328Flag for United States of America

asked on

Using two arrays on one page

I have an array and need to add another to the page - How do I correctly rename the second on to make them both work.  I tried naming the second one $checkbox_array2 but the page bombed.

	$checkbox_array= array(
		'listofcheckbox_options'
	);
	foreach($checkbox_array as $key=>$value) {
		if(is_array($_POST[$value])) {
			$_POST[$value] = "|" . implode('|,|',$_POST[$value]) . "|";
		} elseif($_POST[$value]) {
			$_POST[$value] = "|" . $_POST[$value] . "|";
		} else {
			$_POST[$value] = "";
		}

Open in new window


Thanks,
John
ASKER CERTIFIED SOLUTION
Avatar of Kim Walker
Kim Walker
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JohnMac328

ASKER

Or have you placed this string here as a placeholder for the real values?

Yes - puling values from one table - I have another table with values I also want to pull in the same way - When I changed the name and listed the different table it bombed
Please be specific. How did it "bomb"? Where is the rest of the code? There must be more after line 11. Show us the code with the new name. Can you post a link to the page?
It is inside a CMS system and not public - The system throws an error that it can't display the page.  

Here is the complete code

$checkbox_array= array(
		'listfromtable'
	);
	foreach($checkbox_array as $key=>$value) {
		if(is_array($_POST[$value])) {
			$_POST[$value] = "|" . implode('|,|',$_POST[$value]) . "|";
		} elseif($_POST[$value]) {
			$_POST[$value] = "|" . $_POST[$value] . "|";
		} else {
			$_POST[$value] = "";
		}
	}
}

Open in new window

Where is the code with $checkbox_array2? That seems to be creating the problem, not this code.
$checkbox_array2= array(
		'listfromtable'
	);
	foreach($checkbox_array2 as $key=>$value) {
		if(is_array($_POST[$value])) {
			$_POST[$value] = "|" . implode('|,|',$_POST[$value]) . "|";
		} elseif($_POST[$value]) {
			$_POST[$value] = "|" . $_POST[$value] . "|";
		} else {
			$_POST[$value] = "";
		}
	}
}

Open in new window

Sorry too many distractions - here is the complete code - now how to add another checkbox_array and pull from a different table

if($_POST) {
	$_POST = array_merge($_POST, usual_fields_post( $this, $this->getItemName('KD_list',$lid), array('item_active','created') ) );
	$_POST = array_merge($_POST, array('KD_user_item_id'=>$this->db_user_row['item_id']) );

	///////////////////////////////////////	
	// collect arrays of checkboxes
	$checkbox_array= array(
		'listfromtable'
	);
	foreach($checkbox_array as $key=>$value) {
		if(is_array($_POST[$value])) {
			$_POST[$value] = "|" . implode('|,|',$_POST[$value]) . "|";
		} elseif($_POST[$value]) {
			$_POST[$value] = "|" . $_POST[$value] . "|";
		} else {
			$_POST[$value] = "";
		}
	}
}


portal_process_form($this,$lid,$row);

Open in new window


Here is the code to display items from list

<div class="panel-body">
				'.HTML_checkBoxMulti($this,array(
		'table_name' => "listfromtable",

Open in new window

Ok figured it out.  It can be duplicated with the same name - just needs a different list.

	$checkbox_array= array(
		'listfromtable'
	);
	foreach($checkbox_array as $key=>$value) {
		if(is_array($_POST[$value])) {
			$_POST[$value] = "|" . implode('|,|',$_POST[$value]) . "|";
		} elseif($_POST[$value]) {
			$_POST[$value] = "|" . $_POST[$value] . "|";
		} else {
			$_POST[$value] = "";
		}
	}
}

	$checkbox_array= array(
		'LISTFROMDIFFERENTTABLE'
	);
	foreach($checkbox_array as $key=>$value) {
		if(is_array($_POST[$value])) {
			$_POST[$value] = "|" . implode('|,|',$_POST[$value]) . "|";
		} elseif($_POST[$value]) {
			$_POST[$value] = "|" . $_POST[$value] . "|";
		} else {
			$_POST[$value] = "";
		}
	}
}

Open in new window


Then

<div class="panel-body">
				'.HTML_checkBoxMulti($this,array(
		'table_name' => "listfromtable",

Open in new window


<div class="panel-body">
				'.HTML_checkBoxMulti($this,array(
		'table_name' => "LISTFROMDIFFERENTTABLE",

Open in new window

You were correct - thanks