Wanneer ik een reactie toevoeg aan een nieuwsbericht
werkt prima. Totdat ik 2 of meer reacties er aan toevoegd me webpagina ziet er dan zo uit

News.title
News.date
News.message
Comment.name
Comment.mail
Comment.message

News.title
News.date
News.message
Comment.name(2)
Comment.mail(2)
Comment.message(2)

zoals je ziet news.title, News.date, news.message komen dus dubbel weer, terwijl ik ze maar 1 echo.
erg irritant als je natuurlijk als je 5 reacties heb, dan zie je 5x het bericht .
Hoe kan ik dat oplossen, dat hij gewoon 1x mijn nieuwsbericht geeft en daaronder de geschreven reacties.


code
<?php

$news_id = mysql_real_escape_string($_GET['id']);
$comment_id = mysql_real_escape_string($_GET['id']);

$sql = "SELECT comments.comment_id, comments.comment_name, comments.comment_mail, comments.comment_message, news.news_id, news.news_title, news.news_date, news.news_message FROM comments RIGHT JOIN news ON news.news_id = comments.comment_news_id WHERE news.news_id = ". $news_id." ORDER BY news.news_id";

$result = mysql_query( $sql )
or die( mysql_error() );

if( mysql_num_rows( $result) == 0 )
{
echo "Result = 0";
}

else
{
// While maken
while(
$output = mysql_fetch_assoc( $result) )
{
{
echo '<p class="title">// <a href="getNewsMessage.php?id=' . $output['news_id'] .'">'.$output['news_title'].'</a></p>';

echo '<p class="date">gepost op ' . dutchdate($output['news_date']) . '</p>';
echo '<p class="message">' . htmlspecialchars_decode($output['news_message']) . '</p>';
echo "\n\n";

echo '<p class="comment">' . htmlspecialchars_decode($output['comment_name']) . '</p>';;
echo '<p class="comment">' . htmlspecialchars_decode($output['comment_mail']) . '</p>';
echo '<p class="comment">' . htmlspecialchars_decode($output['comment_message']) . '</p>';
echo "\n\n";

}
}
}

?>
Blijkbaar niet, hij staat 3x op je scherm wanneer je 3 resultaten hebt. En 2x bij 2 resultaten.

Ik zie ook nergens een afsluitende } van de while-lus.
Ik zie 4 { en 2 } dus ik denk dat ie in de while() zit.
toch heb ik nog twee vraagjes

Als er een reacties zijn laat hij toch
Naam:
Mail:
Bericht:
Zien
Hoe kan ik er voor zorgen dat ze pas zichtbaar zijn wanneer er werkelijk reacties pas zijn

<?php

if ($counter_message < 1) {
echo '<p class="title">// <a href="getNewsMessage.php?id=' . $output['news_id'] .'">'.$output['news_title'].'</a></p>';
echo '<p class="date">gepost op ' . dutchdate($output['news_date']) . '</p>';
echo '<p class="message">' . htmlspecialchars_decode($output['news_message']) . '</p>';
echo "\n\n";
echo '<p class="title"> .Reacties</p>';


$counter_message++;
}


echo '<p class="comment">Naam: ' . htmlspecialchars_decode($output['comment_name']) . '</p>';;
echo '<p class="comment">Mail: ' . htmlspecialchars_decode($output['comment_mail']) . '</p>';
echo '<p class="comment">Bericht: ' . htmlspecialchars_decode($output['comment_message']) . '</p><br/>';
echo "\n\n";

?>




en mijn tweede vraag is
elke keer wanneer ik reactie toevoeg
dan zie ik de resultaat niet gelijk op me php pagina
ik moet hem elke keer refreshen om het te laten zien
hoe los ik dit op

post page
<?php
while(
$output = mysql_fetch_assoc( $result ) )

{
{

if ($counter_message < 1) {
echo '<p class="title">// <a href="getNewsMessage.php?id=' . $output['news_id'] .'">'.$output['news_title'].'</a></p>';
echo '<p class="date">gepost op ' . dutchdate($output['news_date']) . '</p>';
echo '<p class="message">' . htmlspecialchars_decode($output['news_message']) . '</p>';
echo "\n\n";
echo '<p class="title"> .Reacties</p>';

$counter_message++;
}


echo '<p class="comment">Naam: ' . htmlspecialchars_decode($output['comment_name']) . '</p>';;
echo '<p class="comment">Mail: ' . htmlspecialchars_decode($output['comment_mail']) . '</p>';
echo '<p class="comment">Bericht: ' . htmlspecialchars_decode($output['comment_message']) . '</p><br/>';
echo "\n\n";

}}}
//Reaction form
if (!isset($_POST['submit'])) {


echo'<br/><form method="post" name="addComment" action="">';
echo'<legend><p class="comment">Reactie (uw ipadres wordt bewaard)</legend>';
echo'<legend><p class="comment">Naam:</legend> <input name="comment_name" size="20" class="comment_name_field"></p>';
echo'<legend><p class="comment">Mail:</legend> <input name="comment_mail" size="20" class="comment_mail_field"></p>';
echo'<legend><p class="comment">Bericht:</legend>';
echo'<textarea cols="30" rows="4" name="comment_message" class="comment_message_field"></textarea></p>';

echo '<br/>';

echo'<input type="submit" name="submit" value="Posten" class="post_button">';
echo'<input type="reset" name="reset" value="Reset" class="post_button">';
echo'</form>';


}

else

{
//INSERT REACTION values
$comment_name = mysql_real_escape_string($_POST['comment_name']);
$comment_mail = mysql_real_escape_string($_POST['comment_mail']);
$comment_message = mysql_real_escape_string($_POST['comment_message']);

$comment_ip = $_SERVER['REMOTE_ADDR'];


$sql = mysql_query("INSERT INTO comments (comment_name, comment_mail, comment_message, comment_ip, comment_news_id) VALUES ('$comment_name', '$comment_mail', '$comment_message', '$comment_ip', '$news_id')");



}
?>

Reageren