我正在开发一个论坛,为此我需要一个评论系统,由于某种原因,我无法解决这个问题,它说明了id,用户名和评论的未定义索引。它完美地显示了日期时间,因此我需要您的帮助来改进我的代码,以便我可以从数据库中的注释表中检索数据[id, username, comments]
并显示删除选项。
我已设法插入注释但不显示它们。这是我每次想在HTML表单上显示注释时调用的函数,还添加一个删除选项,可能是一个X符号来删除所需的注释。
function refresh_comments()
{
$conn=dbConnect();
$sql_query = "SELECT * FROM comments order by id ASC";
$resultSet = $conn->query($sql_query);
if($resultSet->num_rows > 0)
{
while($row = $resultSet->fetch_assoc())
{
echo "<div class='tab '>";
echo "<a href='delete_commentsystem()?id=" . $row['id'] . "'> X</a>";
echo $row['name'];
echo $row['comments'];
echo $row['date_publish']; // this part works but the rest dont
echo "</div>";
}
$conn->close();
}
答案 0 :(得分:-1)
$ row是一个数组。你需要告诉PHP要回应什么结果。
function refresh_comments()
{
$conn=dbConnect();
$sql_query = "SELECT * FROM comments order by id ASC";
$resultSet = $conn->query($sql_query);
if($resultSet->num_rows > 0)
{
while($row = $resultSet->fetch_assoc())
{
echo "<div class='tab '>";
echo "<a href='delete_commentsystem()?id=" . $row['id'] . "'> X</a>";
echo $row['name'][0]; //Set 0 to the row number you want.
echo $row['comments'][0]; //Set 0 to the row number you want.
echo $row['date_publish']; // this part works but the rest dont
echo "</div>";
}
$conn->close();
}