Welcome Guest, Not a member yet? Register   Sign In
populating a checkbox from database
#4

[eluser]nikefido[/eluser]
Hmmm the answer to this seems to be specific to your business logic.

I would create a function within the model you use to call the database query (assuming you handle database calls from a model class) that checks if a product would require a check.

Code:
//possible implementation
<?php  foreach ($query2->result() as $row):?>
<?php if($check = $this->yourmodel->shouldCheckBox($row->product_id)) : ?>
    <p>&lt;?php echo form_checkbox('product', true, set_checkbox());?&gt;
    &lt;?php //$row->product_id; ?&gt;
    &lt;?php echo $row->product; ?&gt;</p>
&lt;?php endif; ?&gt;
&lt;/form&gt;
&lt;?php endforeach ?&gt;

Upon seeing your code, you might be already doing this with your "set_checkbox()" function. However, I'm not sure that your syntax is correct for the form_checkbox();
According to docs, it goes like this:
Code:
//from the docs
$js = 'onClick="some_function()"';

echo form_checkbox('newsletter', 'accept', TRUE, $js)
where you're implementation skips the argument where "accept" goes. You should pass it a default parameter.


Messages In This Thread
populating a checkbox from database - by El Forum - 01-11-2009, 08:27 PM
populating a checkbox from database - by El Forum - 01-11-2009, 09:11 PM
populating a checkbox from database - by El Forum - 01-11-2009, 09:17 PM
populating a checkbox from database - by El Forum - 01-11-2009, 09:31 PM
populating a checkbox from database - by El Forum - 01-11-2009, 09:43 PM
populating a checkbox from database - by El Forum - 01-12-2009, 07:27 AM
populating a checkbox from database - by El Forum - 01-12-2009, 08:22 AM
populating a checkbox from database - by El Forum - 01-15-2009, 08:40 PM
populating a checkbox from database - by El Forum - 01-15-2009, 09:53 PM
populating a checkbox from database - by El Forum - 01-16-2009, 01:23 AM
populating a checkbox from database - by El Forum - 01-16-2009, 06:01 AM
populating a checkbox from database - by El Forum - 01-16-2009, 08:54 PM



Theme © iAndrew 2016 - Forum software by © MyBB