Welcome Guest, Not a member yet? Register   Sign In
checkbox arrays
#1

[eluser]elmne[/eluser]
I'm trying to retrieve checkbox values from an array so that the checked id numbers in the array can be processed.

I do it like this

In the view, i declare the checkbox like this

Code:
<tr>


        <td>&lt;input type="checkbox" name="checkbox[&lt;?php echo $row-&gt;customer_type_id ?&gt;]" value="&lt;?php echo $row->customer_type_id ?&gt;" /></td>    


</tr>

Then when the form is submitted, i try to process it like this

Code:
$checked = $this->input->post('checkbox[]');


        $checked = $this->input->post('checkbox[]');
        $count = count($checked);
        for($i=1; $i < $count; $i++)

Followed by the sql command that uses
Code:
'".$checked[$i]."'
as a parameter.

But it gives me an error. The sql command fails to work even though no error is shown.

What's wrong with the above code?
#2

[eluser]daelsepara[/eluser]
you can try this code:

Code:
$checked = $this->input->post('checkbox');
foreach($checked as $key => $value)
{
// your sql command would then use:
// '".$key."'
//
// where $key is index to your checkbox item
// $value would indicate whether it was checked or not

$sql = "SELECT * from some_table WHERE id = '$key'";
}




Theme © iAndrew 2016 - Forum software by © MyBB