sql server - PHP while loop echoing duplicates -
i need help methodology
i have sql statement fetches results questions 'header table'.
while() info beingness fetched i'm running sql statement pulls comments 'sub table' according id fetched questions table.
when echo together, question number 1's comments show fine, comments related question showing fine.
the issue when question number 2's comments echoed, comments question number 1 show (duplicated).
i can't figure out i'm going wrong.
here's simplified version of code looks show methodology:
$comment_list = ""; // display comments $get_questions = $dbh->prepare("select ..."); // parameters bound here using $get_statements->bindparam(); while($row = $get_questions->fetch(pdo::fetch_assoc)){ $question_id = $row['id']; $question_string = $row['string']; // pull comments $get_comments = $dbh->prepare("select ..."); // parameters bound here using $get_comments->bindparam(); while($row = $get_comments->fetch(pdo::fetch_assoc)){ $comment_id = $row['id']; $comment_string = $row['string']; $comment_list .= " <p>" .$comment_string. "</p> "; } echo " <h1>" .$question_string. "</h1> " .$comment_list. " "; } why duplicates happening when echoing sec question?
you've reset $comment_list variable before sec while loop. set
$comment_list = null ; just before sec while loop. that's !
php sql-server while-loop
No comments:
Post a Comment