Counting selected checkboxes apiece
<p>I have created a form to select category items from main category. Here I use checkboxes to select category item. In my form there are many main categories and have its own subcategories. Example Courses and its subjects. </p>

<p>With this form I need to check how many sub items have selected for a one category. And also I need to look over at least one sub category has selected in all main category and if it is ok want to limit upto 10 sub categories to select. </p>

<p>I tried it something like this.. but here its count all selected subcategories. </p>

<pre><code>if ( isset ( $_POST['sub-category']) &amp;&amp; is_array( $_POST['sub-category'])) {    
    $totalCategory = count( $_POST['sub-category']);

    if ( $totalCategory &gt;= 1 &amp;&amp; $totalCategory &lt;= 10 ) {

        $_SESSION['sub-category'] = $_POST['sub-category'];                 
        $url = BASE_URI . 'register.php'; // Define the URL:        
                header("Location: $url");
                exit(); // Quit the script.         

    } else {        
        echo 'ERROR: Please select atleast 1, not more than 10.';           
    }           
} else {                
    echo 'ERROR: Please select atleast one category.';  
}
</code></pre>

<p><strong>UPDATE:</strong></p>

<p>This is PHP I use to generate from </p>

<pre><code>echo "&lt;input type='checkbox' value='{catId:subID}' name='subject{$lastCatId}[]' /&gt;{$lastCatName}";
</code></pre>

<p>Them HTML generate something like this..</p>

<pre><code>&lt;h3&gt;Main Category 01 
    &lt;input type='checkbox' value='3:4' name='subject3[]' /&gt;sub category
    &lt;input type='checkbox' value='3:6' name='subject3[]' /&gt;sub category

&lt;h3&gt;Main Category 02 
    &lt;input type='checkbox' value='4:6' name='subject4[]' /&gt;sub category
    &lt;input type='checkbox' value='4:2' name='subject4[]' /&gt;sub category

&lt;h3&gt;Main Category 01 
    &lt;input type='checkbox' value='5:8' name='subject5[]' /&gt;sub category
    &lt;input type='checkbox' value='5:4' name='subject5[]' /&gt;sub category
</code></pre>

<p>Problem is how I get sub categories' values separately and then need to count...</p>

<p>I hope someone help me out...
Thank you.</p>
