BigD Posted July 22, 2012 Share Posted July 22, 2012 I want to display a table with 3rd column a radio buttom. Could not figure out this bug in my code. Please help. See attachment. or the displayed code below: <?php include("../mylibrary/login.php"); login(); // attach to DB echo "<table width=\"100%\" cellpadding=\"1\" border=\"1\">\n";// echo "<tr><td colspan=\"4\"><b>Students in this lesson "</b></td></tr>\n";<- something wrong here echo "<tr><td><b>Last Name</b></td><td><b>First Name</b></td><td><b>Attending Status</b></td></tr>\n"; $classname = $_REQUEST['classname']; $ldate = $_REQUEST['ldate']; $cname = $_REQUEST['cname']; $chour = $_REQUEST['chour']; $query = "SELECT classid "; $query .= " from class "; $query .= " where classname = '$classname'"; // echo "class is $classname\n<br>";// echo "SQL is $query\n"; $result = mysql_query($query);//if (!$result) echo "<h2>SQL error</h2>\n". mysql_error(); $row = mysql_fetch_array($result, MYSQL_ASSOC); $classid = $row['classid']; // echo " classid fetched is $classid\n"; // $classid = 7; $query = "SELECT lastname, firstname "; $query .= " FROM student"; $query .= " where classid = $classid"; $query .= " order by lastname"; $result = mysql_query($query); if (!$result) echo "<h2>SQL error</h2>\n". mysql_error(); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $lastname = $row['lastname']; $firstname = $row['firstname']; echo "<tr><td>$lastname</td><td>$firstname</td>"; $absent_status = 'unchecked'; $partiallyThere_status = 'unchecked'; $present_status = 'checked'; if (isset($_POST['phour'])) { $selected_radio = $_POST['gender']; if ($selected_radio == 'absent') { $absent_status = 'checked'; } else if ($selected_radio == 'partiallyThere') { $partiallyThere_status = 'checked'; } else if ($selected_radio == 'present') { $present_status = 'checked'; } }// <body>//<FORM NAME ="form1" METHOD ="POST" ACTION ="radioButton.php">//echo "<td>//<INPUT TYPE = 'Radio' Name ='gender' value= 'present' <?PHP print $present_status; ?>>Present//<INPUT TYPE = 'Radio' Name ='gender' value= 'absent' <?PHP print $absent_status; ?>>absent//<INPUT TYPE = 'Radio' Name ='gender' value= 'partiallyThere' <?PHP print $partiallyThere_status; ?>>partiallyThere,// Hours in class//<INPUT TYPE = "text" Name = "phour" size = 4 ></td>";//<INPUT TYPE = "Submit" Name = "Submit1" VALUE = "Submit">//</FORM>//</body>// echo "<form action=\"updtattd.php\" method=\"post\">\n";// echo " <h2>Class: $classname </h2> <br>";// echo "<h2>Lesson Name: $cname </h2> <br>";// echo "<h2>Lesson Date: $ldate </h2> <br>";// echo "<h2>Credit Hours: $chour </h2> <br>"; echo "<td><input type=\"radio\" name=\"group1\" value=\"1\" checked> Present</td>"; echo "<td><input type=\"radio\" name=\"group1\" value=\"Absent\" > Absent</td>"; echo "<td><input type=\"radio\" name=\"group1\" value=\"PartialPresent\"> Partially there</td>"; echo "<td><input type=\"text\" name=\"phour\" size=\"4\"></td>";// echo "</form>"; //?>//\n"; echo "</table>\n";}?> Link to comment Share on other sites More sharing options...
niche Posted July 22, 2012 Share Posted July 22, 2012 Please post your code (table only) with all the variables. Link to comment Share on other sites More sharing options...
BigD Posted July 23, 2012 Author Share Posted July 23, 2012 Here is the FORM that calls for the PHP code I posted earlier: <h2>Attendance for : </h2><form action="enterattendance.php" method="post"><input type="hidden" name="content" value="quarterly"><table width="100%" cellpadding="1" border="1"> echo "<tr><td>Class</td>\n"; echo "<td><select name=\"cat\">\n"; $query="SELECT classid,classname from class"; $result=mysql_query($query); while($row=mysql_fetch_array($result,MYSQL_ASSOC)) { $classid = $row['classid']; $classname = $row['classname']; echo "<option value=\"$classid\">$classname</option>\n"; } echo "</select></td></tr>\n";//<tr><td>Enter class name (Winter 2011 Night MTTH):</td>//<td><input type="text" name="classname" size="22"></td></tr><tr><td>Enter lesson date (mm/dd/yyyy):</td><td><input type="text" name="ldate" size="10"></td></tr><tr><td>Enter course name (M28,APP17,K10,...):</td><td><input type="text" name="cname" size="8"></td></tr><tr><td>Enter Credit Hours (3.5 or less):</td><td><input type="text" name="chour" size="4" value="3.5"></td></tr></table><input type="submit" name="button" value="Enter Hours"></form> Link to comment Share on other sites More sharing options...
BigD Posted July 29, 2012 Author Share Posted July 29, 2012 I figured it out. I have to create unique group names for each row of radiu buttons. here is the code: <form action="addattn.php" method="post"><?php include("../mylibrary/login.php"); login(); $ldate = $_REQUEST['ldate']; $cname = $_REQUEST['cname']; echo "Attendance for $cname on $ldate\n"; echo "<table width=\"100%\" cellpadding=\"1\" border=\"1\">\n"; echo "<tr><td><b>Last Name</b></td><td><b>First Name</b></td><td><b>Attending Status</b></td></tr>\n"; $classid = $_REQUEST['cat']; $query = "SELECT lastname, firstname, stdid"; $query .= " FROM student"; $query .= " where classid = $classid"; $query .= " order by lastname"; $result = mysql_query($query); if (!$result) echo "<h2>SQL error</h2>\n". mysql_error(); $i = 0; while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $lastname = $row['lastname']; $firstname = $row['firstname']; $stdid = $row['stdid']; echo "<tr><td>$lastname</td><td>$firstname</td>"; $absent_status = 'unchecked'; $partiallyThere_status = 'unchecked'; $present_status = 'checked'; $hours= 3.5; $atnstd[$i] = $stdid; echo "<td><input type=\"radio\" name=\"group.$i\" value=\"1\" checked> Present</td>"; echo "<td><input type=\"radio\" name=\"group.$i\" value=\"Absent\" > Absent</td>"; echo "<td><input type=\"radio\" name=\"group.$i\" value=\"PartialPresent, enter attended hours:\"> Partially there, hours attended:</td>"; echo "<td><input type=\"text\" name=\"phour\" size=\"4\"></td>"; if (isset($_POST['phour'])) { $selected_radio = $_POST['gender']; if ($selected_radio == 'absent') {$hours = 0; $absent_status = 'checked'; } else if ($selected_radio == 'partiallyThere') {$hours = $phour; $partiallyThere_status = 'checked'; } else if ($selected_radio == 'present') {$hours= 3.5; $present_status = 'checked'; } } $atnhrs[$i] = $hours; $i = $i +1; print_r($atnhrs); } echo "</table>\n";?><input type="submit" name="button" value="update"></form> Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now