Home › Forums › Back End › Try out my first PHP web app! › Reply To: Try out my first PHP web app!
September 21, 2014 at 5:05 pm
#183795
Participant
Regarding this:
while ($row = mysqli_fetch_array($comments)) {
$comment = htmlentities($row['comment']);
$comment_by = $row['comment_by'];
?>
<div id='commentbox'>
<p><?php echo $comment;?></p>
<span class='detail1' id='username'><?php echo $comment_by;?></span>
<button onclick='post()'>Click</button>
</div>
<?
}
Why are you using an ID rather than a data-*
attribute as discussed above? It would work fine, while using an ID would create multiple duplicate IDs on the page (which is invalid; every ID must be unique).
<div id="commentbox" data-username="<?php echo $comment_by ?>">
<p><?php echo $comment;?></p>
<button onclick="post()">Click</button>
</div>