0

i am populating rows of html table with some data as shown in code below ! I want to allow user to select multiple rows of this html table (for example using checkboxes but don't know to utilize checkbox in this case) and then i want to add submit button so that user write ONly the selected html table rows to mysql table!(write each rows of html table to a separate mysql table row)

How i should allow user select html table rows and how to write data of multiple html table rows to mysql ?

<?
$postData_value = $_POST['postData'];
$pieces = explode("\n", $postData_value); // make an array out of curl return value
$pieces = array_map('trim', $pieces); // remove unnecessary space
$pieces = array_chunk($pieces, 2); // group them by two's

?>

<table id="test" cellspacing="0" border="1">
        <tr>

         <th>variable1 title1</th>
         <th>variable2 title2</th>
         <th>variable3 title3</th>
         <th>variable4 title4</th>
         <th>variable5 title5</th>
         <th>variable6 title6</th>
         <th>variable7 title7</th>

        </tr>

<?
foreach($pieces as $key => $value){
                 .....
                 .....
                 .....

       echo ("<tr><td>$variable1</td>");
       echo ("<td>$variable2</td>");
       echo ("<td>$variable3</td>");
       echo ("<td>$variable4</td>");
       echo ("<td>$variable5</td>");
       echo ("<td>$variable6</td>");
       echo ("<td>$variable7</td></tr>");

}

?>

</table>
user1788736
  • 2,727
  • 20
  • 66
  • 110
  • when you build your form/input elements, name them as arrays `name=field[0]`, and give the checkbox the same key as all the inputs on the same row. Then on form submit you can get the keys of all the posted checkboxes, and only insert the row values with the same key. – Sean Sep 17 '15 at 17:21
  • how to display my data so user select each row of html table ? before i try write those rows to mysql table! – user1788736 Sep 17 '15 at 17:40
  • look at @Barmar's answer on the duplicate question http://stackoverflow.com/a/14010338/689579, as it shows how to build html in a loop. – Sean Sep 17 '15 at 17:57
  • I know how to create html in loop as you see i am looping an array in above posted code! I just dont know how to select each row ( entire row)of html table data then send those 7 row varibles to mysql! I want give user choice to selet rows otherwise i could directly write all the rows to mysql! – user1788736 Sep 17 '15 at 19:35

0 Answers0