JohnMac328
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.
Thanks,
John
$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] = "";
}
Thanks,
John
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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?
ASKER
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
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] = "";
}
}
}
Where is the code with $checkbox_array2? That seems to be creating the problem, not this code.
ASKER
$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] = "";
}
}
}
ASKER
Sorry too many distractions - here is the complete code - now how to add another checkbox_array and pull from a different table
Here is the code to display items from list
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);
Here is the code to display items from list
<div class="panel-body">
'.HTML_checkBoxMulti($this,array(
'table_name' => "listfromtable",
ASKER
Ok figured it out. It can be duplicated with the same name - just needs a different list.
Then
$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] = "";
}
}
}
Then
<div class="panel-body">
'.HTML_checkBoxMulti($this,array(
'table_name' => "listfromtable",
<div class="panel-body">
'.HTML_checkBoxMulti($this,array(
'table_name' => "LISTFROMDIFFERENTTABLE",
ASKER
You were correct - thanks
ASKER
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