How can I create a html table using PHP MVC

by Cracks   Last Updated April 16, 2019 02:05 AM

I am using PHP MVC with PDO. In my User model I have the following

public function selectAll(){
    $stmt = $this->_connection->prepare("SELECT * FROM users ORDER BY user_id ASC");
    $stmt->execute();
    return $results = $stmt->fetchAll();
}

I then have this in a controller

        $user= $this->model('User');
        $user->selectAll();

View Currently tried this but i get Undefined variable: users in F:\xampp\htdocs\app\views\users.php on line 28

                    <tr>
                        <th>ID</th>
                        <th>Name</th>
                        <th>Username</th>
                    </tr>
                    <?php foreach ($user as $row) {

                    ?>
                    <tr>
                        <td><?php=$row['user_id'];?></td>
                        <td>name</td>
                        <td>user/td>
                    </tr>
                    <?php
                    }
                    ?>

Most places I see don't use MVC and have what I have in my model directly in the view, but I don't want this.

How can I create a HTML table with MVC?

Tags : php


Related Questions