Skip to content Skip to sidebar Skip to footer

Multiple Checkboxes With Php In Table

I'm trying to build a simple attendance script which has the members in the users table. I have a script which builds the table and shows me today's date along with the rest of the

Solution 1:

Here is the solution based on screen shots.

<?phppublicfunctionviewall() {

    $sth = $this->db->prepare("SELECT * FROM users");
    $sth->execute();

    /* Fetch all of the values of the first column */$result = $sth->fetchAll(PDO::FETCH_ASSOC);
    $startDate = new DateTime();
    $endDate = new DateTime('2013-09-31');

    echo"<table>
     <tr>
     <th>Firstname</th>
     <th>Lastname</th>"; 

    for ($c = clone$startDate; $c <= $endDate; $c->modify('+1 day')) {
        echo"<th>".$c->format('d')."</th>";  
    }
    echo"</tr>";

    foreach($resultas$row) {
        echo"<tr>";
        echo"<td>" . $row['firstname'] . "</td>";
        echo"<td>" . $row['lastname'] . "</td>";

        for($c = clone$startDate; $c <= $endDate; $c->modify('+1 day')) {
               echo"<td><input type='checkbox'/></td>";  
        }

        echo"</tr>";
    }

    echo"</table>";

}

?>

EDIT: added clone to copy the object correctly

Solution 2:

I am not very clear about your problem, but I think the following codes may help:

publicfunctionviewall() 
{
  $sth = $this->db->prepare("SELECT * FROM users");
  $sth->execute();

  /* Fetch all of the values of the first column */$result = $sth->fetchAll(PDO::FETCH_ASSOC);
  $startDate = new DateTime();
  $endDate = new DateTime('2013-09-31');
  $days = array();

  echo"<table>
          <tr>
            <th>Firstname</th>
            <th>Lastname</th>";    
  for ($c = $startDate; $c <= $endDate; $c->modify('+1 day')) 
  {
    echo"<th>" . $c->format('d') . "</th>"; 
  }   
  echo"</tr>";

  foreach ($resultas$row) 
  {
    $firstname = $row['firstname'];
    $lastname = $row['lastname'];
    echo"<tr>";
    echo"<td>$firstname</td>";
    echo"<td>$lastname</td>";
    $startDate = new DateTime();
    $endDate = new DateTime('2013-09-31');
    for ($c = $startDate; $c <= $endDate; $c->modify('+1 day')) 
    {
      echo"<td><input type='checkbox'/></td>"; 
    }     
    echo"</tr>";
  }

  echo"</table>";
}

I can not access db, so I cann't test it, what I want to say is that, tr or th stand for a table line, td is children, every line's children's count should be same.

Post a Comment for "Multiple Checkboxes With Php In Table"