I have two tables in the database, one listing the posts made and the other one of the registered users.
Columns that I have in the posts table:
ID || TEXTO || ID_USER ||
Columns that I have in the user table:
ID || NOME_USER || SENHA_USER||
When you make a post, the system takes the ID
of the user who is posting and registers the data.
Only having problem to work better with both tables, I actually want to make an association between both tables. Because I want to associate the ID_USER
registered in the post table and associate ID
with the user name.
I tried to do this:
("SELECT * FROM posts WHERE ID_USER in (SELECT ID FROM users)")
But it did not work.
At the moment the posts displayed look like this:
3 said :: Text that ID 3 user posted
But I want them to look like this:
Carlos said :: Text that ID 3 user posted
This is all PHP that I'm using to display posts:
<?php
$rs = $pdo->query("SELECT * FROM posts ORDER BY ID DESC ")->fetchAll();
$count = count($rs);
if($count == 0){ echo "Nada foi encontrado"; }else{
if(!$rs){
print_r($pdo->errorInfo());
}foreach ($rs as $res)
{
?>
<?php echo $res['ID_USER'] ?> disse :: <?php echo $res['TEXTO'] ?>
<?php } ?>