purple Posted November 11, 2013 Share Posted November 11, 2013 Actually, i want to do like this.This attendance system for my school.When a teacher chose class, list of student name will appear in a table. Students and class are in a database. Besides students's name there will be two radio buttons to chose. Hope that somebody can help me. Link to comment https://forums.phpfreaks.com/topic/283789-how-to-use-radio-button-in-attendance-system/ Share on other sites More sharing options...
requinix Posted November 11, 2013 Share Posted November 11, 2013 Wouldn't checkboxes be easier? Teacher checks the students who are attending. Regardless, what code do you have now and what doesn't work? Link to comment https://forums.phpfreaks.com/topic/283789-how-to-use-radio-button-in-attendance-system/#findComment-1457831 Share on other sites More sharing options...
purple Posted November 11, 2013 Author Share Posted November 11, 2013 Thanx for your time.Let look at attendance.php <html> <table> <tr> <td><fieldset> <legend class="style58"></legend> <center> <table width="750" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF"> <tr> <td width="56"> </td> <td width="284"><label></label></td> <td width="410"> </td> </tr> <tr> <form id="form1" name="form1" method="post" action="attendance display.php"> <td> </td> <td><span class="style57"> <label>Form</label> </span></td> <td><select name="Form" id="form" > <option>Please Select</option> <option>Four</option> <option>Tw0</option> </select></td> </tr> <tr> <td> </td> <td><span class="style57"> <label>Class</label> </span></td> <td><select name="class" id="class"> <option>Please Select</option> <option>Yellow</option> <option>Black </option> </select></td> <td> </td> <tr> <td> </td> <td align="right"> </td> <td> </td> </tr> </table> <p align="center"> <center> <input type="submit" name="Submit" value="Enter" align="center"/> </form></center> </p> </table> </html> Link to comment https://forums.phpfreaks.com/topic/283789-how-to-use-radio-button-in-attendance-system/#findComment-1457834 Share on other sites More sharing options...
purple Posted November 11, 2013 Author Share Posted November 11, 2013 After teacher chose the class, name of student in the class will display in a table with radio buttons. Here the code that i make, but i know i do many mistake on my code. attendance display.php <form action="index4process.php" method="post"> <table> <tr> <td> </td> <td align="right"><div align="left" class="style48"><span class="style8">Date</span></div></td> </tr> <td> </td> <td> </td> </table> <table border='1' align='center'> <tr> <th width="30"><font size="2">No</font></th> <th width="300"><font size="2">Student's Name</font></th> <th width="250"><font size="2">IC Number</font></th> <th width="250"><font size="2">Status</font></th> </tr> <?php mysql_connect("localhost", "root", "")or die(mysql_error()); mysql_select_db("attendance"); $a7=$_POST["class"]; $search=mysql_query("SELECT*from student where class='$a7' ")or die (mysql_error()); $nombor=1; while($data=mysql_fetch_array($search)) { $a=$data['nama']; $b=$data['no_ic']; ?> <tr> <td><?php echo $nombor ?></td> <td><?php echo $a ?></td> <td><?php echo $b ?></td> <td> <input type="radio" name="Present<?php echo $nombor; ?>" value="Present" >Hadir <input type="radio" name="Present<?php echo $nombor; ?>" value="Absent">Tidak Hadir </td> </tr> <?php $no++; } ?> </center> </table> <center> <label> <input type="submit" name="Submit" value="Sent" onSubmit="doSomething()" /> </label> </center> </form> Link to comment https://forums.phpfreaks.com/topic/283789-how-to-use-radio-button-in-attendance-system/#findComment-1457835 Share on other sites More sharing options...
purple Posted November 11, 2013 Author Share Posted November 11, 2013 Actually, i am not familiar with ajax. This is my first time. Link to comment https://forums.phpfreaks.com/topic/283789-how-to-use-radio-button-in-attendance-system/#findComment-1457837 Share on other sites More sharing options...
codefossa Posted November 11, 2013 Share Posted November 11, 2013 Without going into the security and whatnot you'll need to do such as logins or whatever for the person taking attendance. Here's a little example. Demo: http://lightron.org/tmp/51/ index.php - Making the Form <?php /* * By this point you should have the list of users drawn from * the database. I'm just going to use $users for this. * * They should have an ID and name which would be for the use of * the one taking attendance. */ $users = array( 23 => "Arnold Jackson", 41 => "Jack Thompson", 43 => "James Camron", 44 => "Cindy Loo Hoo", 56 => "Alison Spangler" ); ?> <form id="attend" method="post" action="#" autocomplete="off"> <?php foreach ($users as $id => $user) echo '<input type="checkbox" name="present[]" value="' . $id . '" /> ' . $user . '<br />'; ?> <input type="submit" value="Send" /> </form> <div id="status"></div> script.js - Submit with Javascript (Using jQuery) $(document).ready(function() { function disableForm(disabled) { $("#attend").find("*").attr("disabled", disabled); } $("#attend").submit(function(e) { var postdata = $(this).serialize(); disableForm(true); $.post('attend.php', postdata, function(data) { $("#status").html(data); disableForm(false); }); return false; }); }); attend.php - Deal with Submitted Data <?php if (isset($_POST['present'])) { foreach ($_POST['present'] as $user) { /* * Now I'm making the assumption that you have a table set up and * it defaults the user to 0 (not present) until changed witht he form. * * $sql = "UPDATE `table` SET `present` = '1' WHERE `id` = '{$user}' LIMIT 1;"; * mysql_query($sql); */ // Just to show something back on the form. echo "{$user} is Present<br />"; } // Probaby better to go with something along the lines of this. echo "<br /><br />The form was successfully submitted."; } ?> Link to comment https://forums.phpfreaks.com/topic/283789-how-to-use-radio-button-in-attendance-system/#findComment-1457900 Share on other sites More sharing options...
purple Posted November 12, 2013 Author Share Posted November 12, 2013 Thanx Xaotique.. Link to comment https://forums.phpfreaks.com/topic/283789-how-to-use-radio-button-in-attendance-system/#findComment-1457968 Share on other sites More sharing options...
codefossa Posted November 12, 2013 Share Posted November 12, 2013 You're welcome. If you get stuck anywhere, feel free to ask. I should note that you could make that 1 query by appending to your query in the foreach loop instead of doing a new query each time. It would make a bit more sense. Of course, escape everything and whatnot when you do it to avoid anyone taking advantage of that, even though where it sounds like you're using it that wouldn't exactly be a problem. Just better to be safe. Link to comment https://forums.phpfreaks.com/topic/283789-how-to-use-radio-button-in-attendance-system/#findComment-1457969 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.