2016-09-14 4 views
1

Db db2 これまでのコードサンプルではすべての投稿のみが一覧表示されていますが、コメントは1つしか表示されていませんか? コードこれまで1つのコメントしか表示していませんか?while文中のPHP while文ですか?

本当に助けが必要な人は、コーディングとベストを尽くすのに役立つと助けてください。あなたが内部ループで同じ変数$rowを上書きしている

<?php 
include("../db/db.php"); 
{ 

    /*if(isset($_POST["TimeLine"])){*/ 
    $queryposts = "SELECT * FROM post"; 
    $run_query = mysqli_query($con,$queryposts); 
    while($row = mysqli_fetch_array($run_query)){ 
     $post_id = $row["post_id"]; 
     $uid = $row["user_id"]; 
     $content = $row["content"]; 
     $like = $row["total_like"]; 
     $date = $row["date_created"]; 
     $uidpic = $row["profilepic"]; 
     $email = $row["email"]; 
     $pImage = $row["postimage"]; 
     $pVideo = $row["video"]; 
     echo "<b>POST: <b/><hr />". 
      $content."<hr >" 
     ; 


     $querycomment = "SELECT * FROM comment WHERE comment_id = $post_id"; 
     $run_queryb = mysqli_query($con,$querycomment); 
     while($row = mysqli_fetch_array($run_queryb)){ 
      $ComId = $row["comment_id"]; 
      $Comment = $row["comment"]; 
      $ComDate = $row["comment_date"]; 
      $ProfilePicpost = $row["profilepic"]; 
      echo "<b>Comment: <b/><hr />". 
       $Comment."<hr >" 
      ; 
     } 
    } 
} 

enter image description here

+0

各whileループで '$ row'をリセットしています。投稿とコメントには異なる行変数を使用します。 – aynber

答えて

0

事前にありがとうございます。その名前を他のものに変更します。

$queryposts = "SELECT * FROM post"; 
$run_query = mysqli_query($con,$queryposts); 

while($posts = mysqli_fetch_array($run_query)){ 

    // Your post related code 
    $post_id = $posts["post_id"]; 
    $uid = $posts["user_id"]; 
    // Use $posts instead of $row 

    $querycomment = "SELECT * FROM comment WHERE comment_id = $post_id"; 
    $run_queryb = mysqli_query($con,$querycomment); 

    while($comments = mysqli_fetch_array($run_queryb)){ 

     // Your comment related code 
     $ComId = $comments["comment_id"]; 
     $Comment = $comments["comment"]; 
     // Use $comments instead of $row 

    } 
} 
+0

同じ結果$は1つの結果しか表示せず、1つの投稿について次のコメントにループしませんか? – RaydenPe

+0

あなたのデータをデータベースから見せてください。質問のスクリーンショットを追加するか、sqlfiddleへのリンクを追加することができます。 –

+0

https://www.dropbox.com/sh/bress07ynezkt5p/AADmbwE8ZE-5M3YWYa4wo_-Ca?dl=0 – RaydenPe