Following checkbox structure generated dinamically through PHP while loop,
so checkbox name is same for all checkbox name="cols[]"
<li>
<input type="checkbox" name="tab" value="table1"/>
<ul>
<li><input type="checkbox" name="cols[]" value="t1col1"</li>
<li><input type="checkbox" name="cols[]" value="t1col2"</li>
<li><input type="checkbox" name="cols[]" value="t1col3"</li>
</ul>
</li>
<li>
<input type="checkbox" name="tab" value="table2"/>
<ul>
<li><input type="checkbox" name="cols[]" value="t2col1"</li>
<li><input type="checkbox" name="cols[]" value="t2col2"</li>
<li><input type="checkbox" name="cols[]" value="t2col3"</li>
</ul>
</li>
problem is when I read value as bellow in php I unable to differentiate the values of array cols[] according to its parent categories.
what is the solution for this situation
if(isset($_POST['tab']))
{
foreach($_POST['tab'] as $tabs_entry)
{
$query.=$tabs_entry.'~';
if(isset($_POST['cols']))
{
foreach($_POST['cols'] as $cols_entry)
$query.$cols_entry.',';
$query.="-";
}
}
}
echo $query;
whileloop prevent you from changing thenames? Anyway it looks like you could extract the table number from the first 2 characters of the value (t1,t2,etc.)t1col1andt2col2is checked then output ofecho $queryis:table1~t1col1,t2col1,-table2~t1col1,t2col1,-but expected output istable1~t1col1,-table2~t2col2,-