0
I’m a beginner in PHP and I’m making a system where the user can register and register and post, it’s a blogging system. I built the user with SESSION and can display only his data. In my database I have the users table, where are your data and the posts table. What I want to know now, is how I can list in the user profile, only the posts that he made, because the way I did so far, when I display the posts appear posts of all registered users. Here’s my code and thank you to help.
My table where I display the list of posts
<table>
<?php
$postagens = listaPostagens($conexao);
foreach($postagens as $postagem) {
?>
<tr>
<td>
<img src="envios/<?=$postagem['img']?>"/>
</td>
<td>
</span><?=$postagem['localizacao']?>
</td>
<td>
<?=$postagem['texto']?>
</td>
<td>
<?=$postagem['visualizacoes']?>
</td>
<td>
<?=$postagem['curtidas']?>
</td>
<td>
<?=$postagem['compartilhamentos']?>
</td>
</tr>
<?php
}
?>
</table>
</section>
<?php
Function that lists posts:
function listaPostagens($conexao) {
$postagens = [];
$query = mysqli_query($conexao, "select * from postagens");
while($postagem = mysqli_fetch_assoc($query)) {
array_push($postagens, $postagem);
}
return $postagens;
}
As I said, in this way I am selecting posts from all users and need help to list posts only from the currently logged in user.
$query = mysqli_query($conexao, "select * from postagens WHERE idusuario = {$variavelcontendoIDdousuario}");
, replace the columnidusuario
the respective column in your database table and the variable$variavelcontendoIDdousuario
by user id value.– Max Rogério