Chcę wyśwetlić posty z bazy danych, jednocześnie nie drukując kodu html w php. Problem polega na tym że wyświetla wszystkie posty, czyli imie, datę i komentarze, ale przycisk do polubienia wyświetla tylko raz, a chcę aby dla każdego postu był wyśwetlany przycisk z innym id. Może wie ktoś jak rozwiązać ten problem ?
<div class="row d-flex justify-content-center">
<div class='col-xl-6' >
<div class='row' >
<div class='btn-block d-flex justify-content-between'>
<div><?php echo $display->display_post('last_name') ?></div>
<div><?php echo $display->display_post('time_to_add') ?></div>
</div>
</div>
<div class='row'>
<div class='btn-block d-flex justify-content-between'>
<div><?php echo $display->display_post('comment') ?></div>
</div>
</div>
<div class='row'>
<div class='col-12 col-xl-12 d-flex justify-content-between'>
<button class='btn btn-danger' name='dodaj_like'><input type='text' name='like' value="<?php echo $display->display_post('id') ?>"/></button>
</div>
</div>
</div>
</div>
public function getData()
{
$session = $_SESSION['id'];
$query = $this->database->connect()->prepare("SELECT post.id, comment, last_name, time_to_add, request_to_id FROM `post` join user on post.user_id = user.id join friend on user.id = friend.request_from_id where request_to_id = :id and status = 'znajomy'");
$query->bindParam(':id',$session, PDO::PARAM_INT);
$query->execute();
if ($query->rowcount()) {
$row = $query->fetchAll();
}
$this->userData = $row;
}
public function display_post(string $colName)
{
if (! empty($colName)) {
$rows = '';
foreach ($this->userData as $data) {
$rows .= $data[$colName].'<br>';
}
return $rows;
} else {
return '';
}
}