Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you're getting an array of checkbox elements, and they are numeric, you can use array_sum(). Not sure I understand your suggested structure, but I'll give you a code sample here based on the existing form structure. Then I'll post another bit to try to make this simpler for you. Executive summary: You do not need all the variables that are created by this form structure.</p> <pre><code>&lt;?php // RAY_temp_user193.php error_reporting(E_ALL); $total = 0; $inputs = array(); $errors = array(); if (!empty($_POST)) { if (!empty($_POST['ts'])) { foreach ($_POST['ts'] as $ts) { $inputs[] = current(explode(' |', $ts)); } } else { $errors[] = 'Tosilog'; } if (!empty($_POST['cs'])) { foreach ($_POST['cs'] as $cs) { $inputs[] = current(explode(' |', $cs)); } } else { $errors[] = 'Chiksilog'; } if (!empty($_POST['ps'])) { foreach ($_POST['ps'] as $ps) { $inputs[] = current(explode(' |', $ps)); } } else { $errors[] = 'Porksilog'; } // IF ERRORS if (!empty($errors)) { echo 'UNABLE TO PRINT COMPLETE TOTAL. MISSING: ' . implode(',', $errors); } $total = array_sum($inputs); if ($total) echo "&lt;br/&gt;TOTAL: $total &lt;br/&gt;" . PHP_EOL; // END OF THE ACTION SCRIPT } // CREATE THE FORM $form = &lt;&lt;&lt;ENDFORM &lt;form method="post"&gt; &lt;input name='ts[]' type='checkbox' value='40 |Tosilog'/&gt; Tosilog &lt;br&gt; &lt;input name='cs[]' type='checkbox' value='40 |Chiksilog'/&gt;Chiksilog &lt;br&gt; &lt;input name='ps[]' type='checkbox' value='45 |Porksilog'/&gt;Porksilog &lt;br&gt; &lt;input type="submit" value= "Total"&gt; &lt;/form&gt; ENDFORM; echo $form; </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