Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] Foreach with implode comma
#3

If it's only about the text value, why don't you assign that as the value attribute of the checkbox?
PHP Code:
<input type="checkbox" name="check_list[]" value="love">love<br

If you need both the number and the text, I would suggest getting the id's and names from your database and put them into an array (in your controller):
PHP Code:
$info = array();
$query $this->db->query("SELECT id,text_name FROM info");
foreach (
$query->result() as $i) {
 
  $id $i->id;
 
  $info[$id] = $i->text_name;
}
// result of this is: $info[1] = 'love', $info[2] = 'heart' etc.

$tags $this->input->post('check_list');
$selected = array();
foreach (
$tags as $t) {
 
   $selected[] = $info[$t];
}
$endresult implode(',' $selected);
// result of this: the "names" of the selected textboxes, seperated by comma's, so no comma after the last one. 
Reply


Messages In This Thread
[SOLVED] Foreach with implode comma - by waptik - 08-01-2016, 10:21 PM
RE: struggling with foreach using checkbox values - by Wouter60 - 08-05-2016, 01:47 AM



Theme © iAndrew 2016 - Forum software by © MyBB