0
E ae Personal, blz? People, I have a little problem, I have 3 SQL tables, a so-called students, another so-called collaborator and another of posts
On the table students we have:
id
nome;
img;
email;
pass;
end;
status
matricula
dash
...
On the table collaborativer we have:
id
nome
img
email
pass
end
status
codigo
And on the table posting we have:
id
id_user (id do usuário q postou a publicação)
publicacao
img
date
My problem is this, I have a connection to table posting:
<?php
$sqlPublic = "SELECT * FROM postagem ORDER BY id DESC";
$resultPublic = mysqli_query($conn, $sqlPublic);
?>
And I have a While
to present all publications in this way:
<?php while ($public = mysqli_fetch_array($resultPublic)) { ?>
<div class="publicacao">
div class="headerPost">
<?php
$id_Post = $public['id']; //A partir daqui pega os dados da publicação do $public que está sendo feita no while com array;
$id_user = $public['id_user'];
$postagem = $public['postagem'];
$datePost = $public['datePost'];
$sqlPostUser = "SELECT * FROM alunos WHERE id = '$id_user'"; // Aqui eu faço a conexão com a tabela alunos com sql_assoc para associar cada publicação com o usuário que à postou com referência no ID do usuário, com o id cadastrado na publicação.
$queryPostUser = mysqli_query($conn, $sqlPostUser);
$linhaAssoc = mysqli_fetch_assoc($queryPostUser);
$dasheres = $linhaAssoc['dash'];
?>
<div class="arPer">
<div class="perfilPost">
<div class="perfilFoto">
<img src="../arquivs/perfil/<?php echo $linhaAssoc['img']; ?>" />
</div>
<a href=""><h1><?php
$linhaNameAssoc = $linhaAssoc['name_user'];
$linhaNameAssoc = explode(" ", $linhaNameAssoc);
echo $linhaNameAssoc[0]." ".$linhaNameAssoc[1];
?></h1></a>
</div>
</div>
</div>
O restante do código é apenas a estrutura normal...
Going on... The problem is this, I can list with while
all publications, so far beauty, only that, as you can see only reference with the table students, and also need to do with the table collaborator, why if a contributor posts in the form it is, will not appear his data, and will give error in the display, I tried to make several ways the selection of the two tables (students & collaborator), but I couldn’t, I tried using UNION
but I couldn’t, I tried with JOIN
, but for this case it does not serve, I had almost the same problem with the listing of users, but I managed to solve, this is still a little more complicated, please, who can help me reply there, wanted to select the two tables to be able to display the posts correctly... I’ll try something that comes to mind now, but just really test
I AM SORRY FOR THE SIZE OF THIS.
kkkkkk Vllw for the support of the gambiarra kkkkk Aah, and your idea helped me, I’m still going to test it, but it helped me because it enlightened me on how to use JOIN, because I had a lot of doubt about it, obg really worth
– Breno Castro