mercredi 20 octobre 2021

Impossible join articles to comments PHP & SQL

i'm a new web developper and I'm learning Php. For my certificate I need to do a PHP blog using OOP MVC architecture. So I try with someone's MVC framework and I can't join the Articles and Comments table, Either all the comments appear under all the articles, or none appear. and article_id stays at 0, maybe the problem is there? Can you help me guys, I'm stuck like 2 days on it.

Thank you very much,

https://i.stack.imgur.com/I3HY6.png and the code :

private $dbcomm;

        public function __construct(){
            $this->dbcomm = new Database;
        }

        public function getComm(){
            $this->dbcomm->query('SELECT *,
                                    comments.article_id as commentsId,
                                    users.created_at as userCreated,
                                    comments.created_at as commentsCreated
                                    FROM comments
                                    INNER JOIN users ON comments.user_id = users.id
                                    INNER JOIN posts ON comments.article_id = posts.id
                                    ORDER BY comments.created_at DESC');


            $results= $this->dbcomm->resultSet();

            return $results;
        }



Aucun commentaire:

Enregistrer un commentaire