Home > OS >  How to take Input As Table and Submit in Mysql Table
How to take Input As Table and Submit in Mysql Table

Time:03-26

I am Trying to make a Result Management System where I take the Students names from Mysql Database and Each have a Unique Id. I want to Render it as a Table Where There Were Be Rows And Columns. I have Also Done but How can I use $_POST and Save it in the Mysqli as there are 100 Values. The thing I done is :

        php

   while ($student_row = mysqli_fetch_assoc($res){
        <input type = "number" name = "mark1-<?php echo $student_row['roll']">
        }

I have Done And Now I get All values by $_POST but it is difficult to define every variable and then submit it to the MySql Table.

If I can Do With Any Library then Please Tell.

Like the Image Given : Like This Image I want to Make

CodePudding user response:

This may help, even if the question is not really clear (for me), but if you write your input name this way:

<input name="students[id_of_the_student][ppt]"/>
<input name="students[id_of_the_student][ma]"/> 
<input name="students[id_of_the_student][nb]"/>...

You'll have this in your post var:

var_dump($_POST["students"]);
/*
array(1) { // quantity of students in table
  [id_of_student]=> array(2)//number of inputs
  {
    [ppt] = "PPT value",
    [ma] => "MA value"
  }
}
*/

Edit: This is how your table/form should look like:

<form id="form-students" method="POST" >
    <table>
        <thead>
            <th>PPT</th>
            <th>MA</th>
            <th>MB</th>
            <!-- And so on... -->
        </thead>
        <tbody>
            <?php while($student_row = mysqli_fetch_assoc($res)) : ?>
                <tr>
                    <?php foreach ($student_row as $key => $value) : ?>
                        <td><input type="text" name="students[<?= $student_row['id'] ?>][<?= $key ?>]" value="<?= $value ?>"></td>
                    <?php endforeach ?>
                </tr>
            <?php endwhile;?>
        </tbody>
    </table>
</form>

<?php 
$students = $_POST['students'];
?>
  • Related