Page 1 of 1

Checkbox Toggle

Posted: Sun Apr 14, 2013 6:10 pm
by azmal101

 <?php  
 $con=mysqli_connect("localhost","root","","User_db");  
 // Check connection  
 if (mysqli_connect_errno())  
   {  
   echo "Failed to connect to MySQL: " . mysqli_connect_error();  
   }  

 $result = mysqli_query($con,"SELECT * FROM Assessments");  

 echo "<table class='sortable' border='0' cellpadding='40'  
cellspacing='0'>  
<thead>  
 <tr>  
 <th>Title</th>  
 <th>Lecturer</th>  
 <th>Start</th>  
 <th>Due</th>  
 <th>Completed</th>  
 </tr>  
 </thead>";  

 while($row = mysqli_fetch_array($result))  
   {  
   echo "<tr>";  
   echo "<td>" . $row['Title'] . "</td>";  
   echo "<td>" . $row['Lecturer'] . "</td>";  
   echo "<td>" . $row['Start'] . "</td>";  
   echo "<td id='Due'>" . $row['Due'] . "</td>";  
   echo "<td>" ."<input type='checkbox' id='mycheckbox' name='Completed' value='Completed' />";  
   echo "</tr>";  
   }  
 echo "</table>";  

 mysqli_close($con);  
 ?>
Hello guys I was wondering if the checkbox would get check when the date on $row['Due'] is reached for example 14/04/2013 is the date on Srow['Due']. The checkbox should automatically get the date and check the checkbox permanently.

Re: Checkbox Toggle

Posted: Mon Apr 15, 2013 11:04 pm
by ExtremeGaming
You're going to need to use the php date function.
<?php
If($row['date'] == date(stuff)) {
// use the checked property of the checkbox
} else {
// use a normal checkbox
}
?>

Re: Checkbox Toggle

Posted: Tue Apr 16, 2013 7:07 am
by Helx
If it's the HTML bit you're unsure of, the following will check the box by default (use it alongside ExtremeGaming's suggestion):
<input type="checkbox" name="travelMethod" value="bike" checked>I use a Bike
And if you don't want the user to be able to un-check the box:
<input type="checkbox" name="travelMethod" value="bike" checked disabled>I use a Bike 
However, do not rely on the "disabled" part of the input.
This can be modified client-side to be a normal editable checkbox.