select one radio button from each row and then submit it to database mysqli

bobby gotecha
    <?php
    include('connect.php');
    $query=mysqli_query($conn,"select * from users") or die("unable to connect");

    ?>
    <html>
    <head>
    </head>
        <body>


            <h2 align="center"> student list</h2>
            <form action="radio.php" method="post"> 
            <table align="center" border="1" cellspacing="0" cellpadding="0" width="700">
                <thread>
                    <td align='center'>id</td>
                    <td align='center'>enrolloment_no</td>
                    <td align='center'>first_name</td>
                    <td align='center'>last_name</td>
                    <td align='center'>attendance&nbsp;&nbsp;&nbsp;</td>

                        </thread>

            <?php
                $i=1;
                while($row=mysqli_fetch_array($query,MYSQLI_BOTH))
                    {
                    echo "<tr>
                    <td align='center'>".@$i."</td>

<td align='center'>".@$row['enrolloment_no']."</td>
<td align='center'>".@$row['first_name']."</td>
<td align='center'>".@$row['last_name']."</td>
<td align='center'>


<input type=\"radio\" name=\"a\" value=\"present\">present

<input type=\"radio\" name=\"a\" value=\"absent\">absent

</tr>

";
            $i++;
                        }   

                ?>

                </table>
                <input type="submit" value="submit">
                        </form>
                </body>



        </html>

The above mentioned code contains a attendance page form which contains radio buttons but the main problem in the above code is i am unable to select radio button from each row as i need to select radio button from each row that is either student would be present or absent so please if anyone has any suggestions how to select one radio button either present or absent from each row and then submit to database.

Mart

You can create a number increasing by each row, or better, set this integer equal to the row's corresponding identifier in your database.

Add a hidden input with name="rowIDs[]" & value="{theIdentifier}".

When you set the name of your row's radio button to "a_{theIdentifier}" you can run a foreach in your PHP script.

might this be what you are looking for?

global example in your code:

 $i=1;
    while($row=mysqli_fetch_array($query,MYSQLI_BOTH)){
       echo "<tr>
       <td align='center'>".@$i."</td>
       <td align='center'>".@$row['enrolloment_no']."</td>
       <td align='center'>".@$row['first_name']."</td>
       <td align='center'>".@$row['last_name']."</td>
       <td align='center'>
         <input type=\"hidden\" value=\"".$row['enrolloment_no']."\" name=\"rowIDs[]\" />
         <input type=\"radio\" name=\"a_".$row['enrolloment_no']."\" value=\"present\">present
         <input type=\"radio\" name=\"a_".$row['enrolloment_no']."\" value=\"absent\">absent
       </td>
       </tr>
       ";
       $i++;
   } 

Now in the submission:

$rowIDs = $_POST['rowIDs'];
foreach($rowIDs as $rowID) {
   $radioButtonValue = $_POST['a_'.$rowID];
   mysqli_query("update `yourtable` SET `attendance` = '".$radioButtonValue."' WHERE `enrolloment_no` = '".$rowID."'");
}

(to do this, replace $i by $row['enrolloment_no'])

ps i made some mistakes i just edited.

When you add these inputs on the top of the form, or bottom.. but IN the form tags Present
Absent
Use master attendance
Then in the submission php part:

if(isset($_POST['useMasterAttendance'])) {
  $masterAttendanceValue = $_POST["masterAttendance"];
  $rowIDs = $_POST['rowIDs'];
  foreach($rowIDs as $rowID) {

     mysqli_query("update `yourtable` SET `attendance` = '".$masterAttendanceValue."' WHERE `enrolloment_no` = '".$rowID."'");
  }
}else {
//DO THE CODE FOR EACH ROW LIKE ABOVE
}

Sorry if i made any typos

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Select one Gridview row with radio button ASP.NET

From Dev

Select a row from data table to show radio button value

From Dev

Checking at least one radio button is selected from each radiogroup in android?

From Dev

select count of rows from 2 tables and merge into one row (mysqli)

From Dev

OnClick submit Insert Radio Button value into Database

From Dev

select radio button from a listview

From Dev

Can only select one radio button on Firefox

From Dev

Select only one in dynamic radio button

From Dev

Submit a page without select a value for a required radio button

From Dev

Submit on Radio button change

From Dev

How to submit forms using radio button one at a time

From Dev

Deleting a ROW from MySQL database using MySQLi

From Dev

Check Radio Button & Select Dropdown List According To Value Retrieved From Database in JSP

From Dev

Check Radio Button & Select Dropdown List According To Value Retrieved From Database in JSP

From Dev

Select one of the radio buttons and click Submit which redirects other url

From Dev

Loop through each row, create button for each record. Cannot get image from database

From Dev

How to get value from mysql database row by row after each click on button?

From Dev

How to select a row in a table and select a specific radio button next to it

From Dev

How to select information from more then one table in MySQL Database using PHP and mySQli, has to be combined single query

From Dev

Pass value from radio button to database

From Dev

Retrieve stored radio button value from database

From Dev

how to load data from a database to a radio button

From Dev

How to select only one dropdown from multiple dropdowns in a list with submit button enable /disable using jquery?

From Dev

Selecting next radio button from selected one

From Dev

Make one button from this three radio

From Dev

MVC razor partial view radio button selection for each row in model

From Dev

MVC razor partial view radio button selection for each row in model

From Dev

Uploading multiple images one to each row PHP and Mysqli db

From Dev

Display JSON data in table format with a submit button corresponding to each row

Related Related

  1. 1

    Select one Gridview row with radio button ASP.NET

  2. 2

    Select a row from data table to show radio button value

  3. 3

    Checking at least one radio button is selected from each radiogroup in android?

  4. 4

    select count of rows from 2 tables and merge into one row (mysqli)

  5. 5

    OnClick submit Insert Radio Button value into Database

  6. 6

    select radio button from a listview

  7. 7

    Can only select one radio button on Firefox

  8. 8

    Select only one in dynamic radio button

  9. 9

    Submit a page without select a value for a required radio button

  10. 10

    Submit on Radio button change

  11. 11

    How to submit forms using radio button one at a time

  12. 12

    Deleting a ROW from MySQL database using MySQLi

  13. 13

    Check Radio Button & Select Dropdown List According To Value Retrieved From Database in JSP

  14. 14

    Check Radio Button & Select Dropdown List According To Value Retrieved From Database in JSP

  15. 15

    Select one of the radio buttons and click Submit which redirects other url

  16. 16

    Loop through each row, create button for each record. Cannot get image from database

  17. 17

    How to get value from mysql database row by row after each click on button?

  18. 18

    How to select a row in a table and select a specific radio button next to it

  19. 19

    How to select information from more then one table in MySQL Database using PHP and mySQli, has to be combined single query

  20. 20

    Pass value from radio button to database

  21. 21

    Retrieve stored radio button value from database

  22. 22

    how to load data from a database to a radio button

  23. 23

    How to select only one dropdown from multiple dropdowns in a list with submit button enable /disable using jquery?

  24. 24

    Selecting next radio button from selected one

  25. 25

    Make one button from this three radio

  26. 26

    MVC razor partial view radio button selection for each row in model

  27. 27

    MVC razor partial view radio button selection for each row in model

  28. 28

    Uploading multiple images one to each row PHP and Mysqli db

  29. 29

    Display JSON data in table format with a submit button corresponding to each row

HotTag

Archive