我试图为我的网站制作一个评论部分,到目前为止我已经完成了显示名称和头像,但没有显示评论文本和日期。 评论表是: id,member_id,comment,date,product_id 问题是我无法在循环中获取结果。我尝试了另一个查询,但它一直给我相同的评论。
<?php
include("includes/db.php");
{
$sql_query="SELECT * FROM product_comm WHERE product_id='$id'";
$result_set=mysqli_query($conn,$sql_query) or die('error');
$get_comm=mysqli_fetch_array($result_set);
$comm_date=$get_comm['date'];
$comm_mem_id=$get_comm['mem_id'];
$comm_text=$get_comm['comment'];
}
{
$sql_query="SELECT * FROM products WHERE str='$str'";
$result_set=mysqli_query($conn,$sql_query) or die('error');
$get_products=mysqli_fetch_array($result_set);
$id=$get_products['id'];
}
{
$sql_query="SELECT * FROM member WHERE id='$comm_mem_id'";
$result_set=mysqli_query($conn,$sql_query) or die('error');
$get_member=mysqli_fetch_array($result_set);
$member_name_first=$get_member['first_name'];
$member_name_last=$get_member['last_name'];
$member_avatar=$get_member['avatar'];
}
$result = mysqli_query($conn,"SELECT id FROM products WHERE str='$str'");
$result = mysqli_query($conn,"SELECT * FROM product_comm WHERE product_id=$id");
$result = mysqli_query($conn,"SELECT * FROM member WHERE id='$comm_mem_id'");
if ($result) {
if($result->num_rows === 0)
{
echo "<center>No comments</center>";
}
else
{
while($row = mysqli_fetch_array($result)) {
echo "
<div class='media'>
<div class='media-left'>
<img src='http://maikatideeba.byethost32.com/images/profile_pics/".$row['avatar']."' class='img-circle' style='width:60px'>
</div>
<div class='media-body'>
<h4 class='media-heading'> ".$row['first_name']." ".$row['last_name']." <small><i> on ".$row['date']." </i></small></h4>
<p> ".$row['comment']." </p>
<hr>
</div>
</div>";
}
}
}
mysqli_close($conn);
?>
正确地将所有内容正确地插入到数据库中,但是当我尝试查看结果时(注释如此)它什么都没有。Result image
答案 0 :(得分:0)
从不必要的查询中清理您的来源。这是一团糟,很难理解你要做的事情。
学习将查询分配给变量,例如:
$sql_members = "SELECT * FROM member WHERE id= ".$comm_mem_id;
$result = mysqli_query( $conn , $sql_members );
以后调试和回显查询要容易得多。 例如,输出是什么:
echo $sql_members;
避免在HTML输出中使用单引号
非常 好奇的 子域名选择...“maikatideeba.byethost32.com”。