Note that there are some explanatory texts on larger screens.

plurals
  1. POCheckbox updating subract quantity codeigniter
    primarykey
    data
    text
    <p>I have a problem with checkboxes when I select one of them. How do I stop the foreach from running if a checkbox has not been checked? Please check my code to fix the issue.</p> <p><em><strong>i want a condition for data unchecked.</em></strong></p> <p><strong>This is my controller:</strong></p> <pre><code>public function create_cargo_manifest(){ $core_model = new Core_m; $core_model-&gt;save_cargo_details(); redirect('core/cargo_lookup/','refresh'); } </code></pre> <p><strong>This is my model:</strong></p> <pre><code>function save_cargo_details() { $data = array(); $waybillno = $this-&gt;input-&gt;post('waybillno'); $quantity = $this-&gt;input-&gt;post('quantity'); $waybilldate = $this-&gt;input-&gt;post('waybilldate'); $declared_value = $this-&gt;input-&gt;post('declared_value'); $consignee = $this-&gt;input-&gt;post('consignee'); $count = count($waybillno); if(empty($waybillno)){ }else{ for ($i = 0; $i &lt; $count; $i++) { $data = array( 'waybillno' =&gt; $waybillno[$i], 'quantity' =&gt; $quantity[$i], 'waybilldate' =&gt; $waybilldate[$i], 'declared_value' =&gt; $declared_value[$i], 'consignee' =&gt; $consignee[$i], ); // SUBRACT REMAINING_QUANTITY // $this-&gt;db-&gt;select('wd.remaining_qty'); $this-&gt;db-&gt;where('wd.waybillno',$waybillno[$i]); $this-&gt;db-&gt;from(self::WAYBILL_DETAILS_TABLE. " as wd"); $query = $this-&gt;db-&gt;get()-&gt;row(); $qty = $query-&gt;remaining_qty; $remaining = $qty - $data['quantity']; $this-&gt;db-&gt;where('waybillno',$waybillno[$i]); $this-&gt;db-&gt;set('remaining_qty',$remaining); $this-&gt;db-&gt;update(self::WAYBILL_DETAILS_TABLE); // INSERT DATA // $this-&gt;db-&gt;insert('sys_cargodetails', $data); } } } </code></pre> <p><strong>This is my view:</strong></p> <pre><code>&lt;?php foreach($waybill_header as $waybill_header) { ?&gt; &lt;?php echo form_open('core/create_cargo_manifest'); ?&gt; &lt;tr style="text-align: center;"&gt; &lt;td&gt;&lt;input type="checkbox" name="waybillno[]" value="&lt;?php echo $waybill_header-&gt;waybillno; ?&gt;"&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $waybill_header-&gt;waybillno; ?&gt;&lt;input type="hidden" &gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $waybill_header-&gt;waybilldate; ?&gt;&lt;input type="hidden" value="&lt;?php echo $waybill_header-&gt;waybilldate; ?&gt;" name="waybilldate[]"&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="text" size="5" value="&lt;?php echo $waybill_header-&gt;remaining_qty; ?&gt;" name="quantity[]"&gt; &lt;input type="hidden" value="&lt;?php echo $waybill_header-&gt;declared_value; ?&gt;" name="declared_value[]"&gt; &lt;input type="hidden" value="&lt;?php echo $waybill_header-&gt;consignee; ?&gt;" name="consignee[]"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;?php } ?&gt; &lt;/table&gt; &lt;input type="submit" value="Save"&gt;&lt;button id="button_cancel" type="button"&gt;Close&lt;/button&gt; &lt;?php form_close(); ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload