I have a simple SELECT function, and I would like to echo the results into a table.
So far I am able to display the results in a linear fashion but not tabular.
Whenever I echo <tr> (see code below) it seems like it's ignored.
What am I doing wrong?
My code so far is;
function.php
class crud {
public function lastLogin() {
$stmt = $this->db->prepare("SELECT * FROM logins WHERE userId=:userId");
$stmt->bindparam(":userId", $_SESSION['user_session']);
$stmt->execute();
if ($stmt->rowCount() > 0) {
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
echo '<tr>'.$row['lastLogin'].'</tr>'; // <- this line
}
}
else {
echo 'Nothing here';
}
return true;
}
}
user.php
<div class="col-lg-6">
<?php $crud->lastLogin(); ?>
</div>
Just to confirm, using the code above does display the data - just not in a table like I want. It's displayed in the following format;
2016-03-07 17:09:382016-03-08 09:12:082016-03-08 09:13:342016-03-08 09:15:022016-03-08 09:15:342016-03-08 11:42:33
I'm sure I am missing something simple. Any help is appreciated.