J'ai pensé à celui-ci depuis un certain temps maintenant, j'ai besoin d'un moyen d'ajouter des réponses aux commentaires dans la base de données, mais je ne sais pas comment procéder.mysql structure pour les commentaires et les réponses de commentaires
Ceci est mon commentaire actuellement la table (ne dit pas grand-chose, mais son démarrage):
CREATE TABLE IF NOT EXISTS `comments` (
`id` int(12) NOT NULL AUTO_INCREMENT,
`comment` text,
`user_id` int(12) DEFAULT NULL,
`topic_id` int(12) NOT NULL,
`ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `user_id` (`user_id`),
KEY `topic_id` (`topic_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=27 ;
et voici ma requête en cours:
SELECT c.id, c.comment, c.user_id, u.username, u.photo
FROM (comments c)
JOIN users u ON c.user_id = u.id
WHERE c.topic_id = 9
Une option serait de créer un nouvelle table appelée "comment_replies" mais je ne suis pas sûr Si je suis capable de sélectionner tous les commentaires et réponses de commentaires dans une requête, et Si j'ajoute une nouvelle colonne appelée "répondre" je ne sais pas comment les trier obtenir chaque commentaire avec chaque réponse.
Je voudrais obtenir des conseils sur la façon de faire face à cela.
Edit:
Après les réponses ci-dessous sur l'ajout de résultat parent_comment_id dans ce type de tableau de 1 commentaire et 2 réponses:
array(2) {
[0]=>
object(stdClass)#17 (7) {
["id"]=>
string(2) "26"
["comment"]=>
string(36) "adding a comment from the admin page"
["user_id"]=>
string(2) "16"
["ts"]=>
string(10) "1249869350"
["username"]=>
string(5) "Admin"
["photo"]=>
string(13) "gravatar2.png"
["reply"]=>
string(23) "There is no admin page!"
}
[1]=>
object(stdClass)#18 (7) {
["id"]=>
string(2) "26"
["comment"]=>
string(36) "adding a comment from the admin page"
["user_id"]=>
string(2) "16"
["ts"]=>
string(10) "1249869350"
["username"]=>
string(5) "Admin"
["photo"]=>
string(13) "gravatar2.png"
["reply"]=>
string(13) "Yes there is!"
}
}
Comment dois-je traiter ce tableau pour travailler avec elle, Est-il possible de séparer le commentaire des réponses?
Quelle est la fonction 'array_search_key' - ce n'est pas une fonction de bibliothèque PHP standard – HorusKol
Comment fonctionne la pagination? – Mrusful
où est la fonction array_search_key ?? existe-t-il en php? –