Only the last item in the array is displayed

1

How to play a code in php, style to a comment system.

Using this code, I was able to make this possible, but in the same way, the code returns only the last query item:

<?php

error_reporting(0);

header("Content-Type: text/html");
header("charset: UTF-8");

$comment_id = $_GET["postID"];

mysql_connect("localhost", "root", "usbw");
mysql_select_db("run");

$cmd = "SELECT * FROM 'comments' WHERE 'POST_ID' LIKE '$comment_id' LIMIT 0,10";
$cmd_q = mysql_query($cmd);

$xmlpath = "";

while($row = mysql_fetch_array($cmd_q)) {
    $xmlpath = "<div id='comment.usr'>" . $row["POST_NAME"] . "</div> disse <div id='comment.content'>" . $row["POST_COMMENT"] . "</div>";
}

?>

<div id="comments">
    <?php echo $xmlpath; ?>
</div>

    
asked by anonymous 11.09.2015 / 16:52

1 answer

3

Place the code snippet <div id="comments"><?php echo $xmlpath; ?></div> within the while so all comments will be printed, not just the last one.

while($row = mysql_fetch_array($cmd_q)) {
    $xmlpath = "<div id='comment.usr'>" . $row["POST_NAME"] . "</div> disse <div id='comment.content'>" . $row["POST_COMMENT"] . "</div>";
    echo '<div id="comments">'. $xmlpath .'</div>';
}

The most equal operand ( += ) only works for numbers, to concatenate strings use the point ( . ) or ( .= ).

    
11.09.2015 / 16:58