php - Send and receive state of unknown number of checkboxes through html form -


i have mysql table , able modify through html form. mysql table has columns this:

id (int) | name (text) | option1 (boolean) | option2 (boolean) 

the number of field options grow on time , not fixed, contains boolean data (0 or 1). number of rows not fixed well.

i modify table html form looks this:

<form action="file.php" method="post">  <table style="width:100%">    <tr>      <th>name</th>      <th>option1</th>      <th>option2</th>    </tr>    <tr>      <th>lili</th>      <th><input type="checkbox" name="lili_1"checked></th>      <th><input type="checkbox" name="lili_2"></th>    </tr>    <tr>      <th>thor</th>      <th><input type="checkbox" name="thor_1" checked></th>      <th><input type="checkbox" name="thor_2" checked></th>    </tr>    <tr>      <th>fred</th>      <th><input type="checkbox" name="fred_1" checked></th>      <th><input type="checkbox" name="fred_2" ></th>    </tr>  </table>  <button type="submit">update</button>  </form>

now gets tricky. when submit form, on server side i don't know how many columns/lines there are. update whole database table (it's small), i need know state of every checkbox columns (option1, option2, ...) , rows (lili, thor, fred,...)

my idea name each checkbox based on column , value of field "name". need send array containing names , columns (because can know boxes checked, not unckecked ones).

on server-side, need recreate matrix array of columns , names , put 1 checkbox checked (through name of checkbox).

this seems error-prone , long implement... such simple task. can points me smarter way to ?

thank you

you can group checkboxes name="thor[]" or name="lili[]" in php backend can retrieve $_request['thor']. remember array. loop foreach($_request['thor'] $thor){} check value if($thor)


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -