-1

I'm trying to make a comment section for my website and I have done so far to display the name and avatar but not the comment text and date. The comment table is : id, member_id, comment,date,product_id The problem is that I cannot fetch the results in a loop. I tried with another query but it keeps giving me the same comment.

<?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>
  &nbsp;<div class='media-body'>
    <h4 class='media-heading'>&nbsp; ".$row['first_name']." ".$row['last_name']." <small><i> on ".$row['date']." </i></small></h4>
  <p> ".$row['comment']." </p> 
<hr>  
</div>

</div>";
}
}
}


mysqli_close($conn);
?>

Everything is being inserted into the database correctly but when I try to view the results (comment like) its nothing..Result image

1 Answers1

0

Clean up your source from unnecessary queries. It's a mess and hard to understand what you are trying to do exactly.

Learn to assign the query to variable, like:

$sql_members = "SELECT * FROM member WHERE id= ".$comm_mem_id;
$result = mysqli_query( $conn , $sql_members );

It's much easier to debug and echo your queries later. For example, what is the output for:

echo $sql_members;

Avoid using single quotes in your HTML output

Very curious sub domain choice ... "maikatideeba.byethost32.com" .

Sayonara
  • 267
  • 1
  • 10