Apologies if i have not posted this correctly…first timer
So I have a web app that communicates with 4 tables(user table, truck table, trailer table, load table). A user can post an item and depending on the category he chooses the item will be posted in the respective table. The users dashboard should print out all the items a user has posted.
I wrote this class:
[php]
class Poster{
public function displayUser($poster_id){
global $pdo;
$query = $pdo->prepare('SELECT * FROM `user` WHERE id=?');
$query->bindValue(1,$poster_id);
$query->execute();
return $query->fetch();
}
public function displayMyPost($poster_id){
global $pdo;
$query = $pdo->prepare("SELECT idtruck as id, title as title, `date`as `date` FROM truck WHERE poster_id = ?
UNION ALL
select idtrailer as id, title as title, `date`as `date` FROM trailer WHERE poster_id =?
UNION ALL
select idload as id, title as title, `date`as `date` FROM `load` WHERE poster_id = ?");
$query->bindValue(1,$poster_id);
$query->bindValue(2,$poster_id);
$query->bindValue(3,$poster_id);
$query->execute();
return $query->fetch();
}
}[/php]
On the users dashboard page i have this code to print out the results in to table:
<table class="table table-bordered table-hover table-striped">
<thead>
<tr>
<th>Post ID</th>
<th>Title</th>
<th>Date posted</th>
</tr>
</thead>
<?php
$poster_id = $user_id;
$myPost = new Poster;
$post = $myPost->displayMyPost($poster_id);
?>
<tbody>
<?php foreach($post as $myPostTest){ ?>
<tr>
<td><?php echo $post['id']; ?></td>
<td><?php echo $post['title']; ?></td>
<td><?php echo $post['date']; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
The problem i am facing is that the table is printing on the first row. It is duplicating the same row the number of times the person has posted an item.