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 month.
I also have a script which prints out the individual users, along side these users I want to have a checkbox in every column as far as the dates stretch out to.
I have a foreach statement for printing the users however if I put the <td><input type="checkbox"/></td>
into this foreach statement this is only filling in the first column of dates.
If I put it in the for statement which outputs my <th>
dates then it appends the checkbox in the <th>
which is not what I want.
I'm not the best programmer so I'm not sure of the method that I should be using to achieve this, what I've done is simple so far if you look below you will be able to see how I've achieved this:
To reitrate the problem is that I am unable to append a checkbox per date value from the code below which prints dates from today's date to whatever it is set to.
Any ideas or input gladly welcomed.
public function viewall() {
$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($result as $row) {
$firstname = $row['firstname'];
$lastname = $row['lastname'];
echo "<tr>";
echo "<td>$firstname</td>";
echo "<td>$lastname</td>";
}
echo "<td><input type='checkbox'/></td></tr>";
echo "</table>";}
PICTURE 1 SHOWS THE PROBLEM
PICTURE 2 SHOWS HOW IT SHOULD LOOK