PHP pdo echo results into table

jonboy

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.

Funk Forty Niner

As stated in comments:

This is an example of table syntax

<table border="1" width="100%"> 
   <tr> 
<td width="100%">ABC</td> 
   </tr> <tr> 
<td width="100%">123</td> 
   </tr> 
</table>

And what you ended up using:

echo '<table><tr><td>'.$row['lastLogin'].'</td></tr></table>';

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related