Débutant en php j'essaie de changer le format de date de ma rubrique "commentaires", j'ai tenté quelque chose mais ça ne marche pas, si quelqu'un veut bien me donner un petit coup de main, je suis preneur.
Pour ma rubrique commentaires j'ai 2 fichiers php.
le 1er : add_comment.php
le 2e : fetch_comment.php
add_comment.php :
Code : Tout sélectionner
<?php
//add_comment.php
$connect = new PDO('');
$error = '';
$comment_name = '';
$comment_content = '';
$email = '';
if(empty($_POST["comment_name"]))
{
$error .= '<p class="text-danger"></p>';
}
else
{
$comment_name = $_POST["comment_name"];
}
if(empty($_POST["comment_content"]))
{
$error .= '<p class="text-danger"></p>';
}
else
{
$comment_content = $_POST["comment_content"];
}
if(empty($_POST["email"]))
{
$error .= '<p class="text-danger"></p>';
}
else
{
$email = $_POST["email"];
}
if($error == '')
{
$query = "
INSERT INTO tbl_comment
(parent_comment_id, comment, comment_sender_name, email)
VALUES (:parent_comment_id, :comment, :comment_sender_name, :email)
";
$statement = $connect->prepare($query);
$statement->execute(
array(
':parent_comment_id' => $_POST["comment_id"],
':comment' => $comment_content,
':comment_sender_name' => $comment_name,
':email' => $_POST["email"]
)
);
$error = '<label class="validation">Ton message a bien été envoyé !</label>';
}
$data = array(
'error' => $error
);
echo json_encode($data);
?>
Code : Tout sélectionner
<?php
//fetch_comment.php
$connect = new PDO('');
$query = "
SELECT * FROM tbl_comment
WHERE parent_comment_id = '0'
ORDER BY comment_id DESC
";
$statement = $connect->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
$output = '';
foreach($result as $row)
{
$output .= '
<div class="separator"</div>
<div class="box-light">
<div class="chapeau">@ <b>'.$row["comment_sender_name"].'</b></div><div class="white"><i>'.$row["date"].'</i></div>
<div class="texte-com">'.$row["comment"].'</div>
<div class="repondre"><button type="button" class="reply" id="'.$row["comment_id"].'">Répondre</button></div>
</div>
';
$output .= get_reply_comment($connect, $row["comment_id"]);
}
echo $output;
function get_reply_comment($connect, $parent_id = 0, $marginleft = 0)
{
$query = "
SELECT * FROM tbl_comment WHERE parent_comment_id = '".$parent_id."'
";
$output = '';
$statement = $connect->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
$count = $statement->rowCount();
if($parent_id == 0)
{
$marginleft = 0;
}
else
{
$marginleft = $marginleft + 5;
}
if($count > 0)
{
foreach($result as $row)
{
$output .= '
<div class="separator"</div>
<div class="box-light" style="margin-left:'.$marginleft.'px">
<div class="chapeau">@ <b>'.$row["comment_sender_name"].'</b></div><div class="white"><i>'.$row["date"].'</i></div>
<div class="texte-com">'.$row["comment"].'</div>
<div class="reponse"><button type="button" class="reply" id="'.$row["comment_id"].'">Répondre</button></div>
</div>
';
$output .= get_reply_comment($connect, $row["comment_id"], $marginleft);
}
}
return $output;
}
?>
sql :
Code : Tout sélectionner
--
-- Database: `testing`
--
-- --------------------------------------------------------
--
-- Table structure for table `tbl_comment`
--
CREATE TABLE IF NOT EXISTS `tbl_comment` (
`comment_id` int(11) NOT NULL,
`parent_comment_id` int(11) NOT NULL,
`comment` varchar(200) NOT NULL,
`comment_sender_name` varchar(40) NOT NULL,
`email` varchar(50) NOT NULL,
`actif` enum('oui','non','attente') COLLATE utf8_unicode_ci NOT NULL,
`date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Indexes for dumped tables
--
--
-- Indexes for table `tbl_comment`
--
ALTER TABLE `tbl_comment`
ADD PRIMARY KEY (`comment_id`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `tbl_comment`
--
ALTER TABLE `tbl_comment`
MODIFY `comment_id` int(11) NOT NULL AUTO_INCREMENT;
Merci et dsl pour la masse de code