1

I ask your help on a subject that I do not really master.

I have two tables: tb_user (NIC_Handle, Pseudo) tb_user_messages_recap (Auteur, Intervenant)

I have to retrieve the NIC_Handle of each 'Pseudo' that corresponds to either 'Auteur' or 'Intervenant'

Can you help me please ?

<?php try{
$MyPDO=$pdo->query("
SELECT 
tb_user_messages_recap.Auteur,
tb_user_messages_recap.Intervenant,
tb_user_messages_recap.Numero,
tb_user_messages_recap.Sujet,
tb_user_messages_recap.Creation,
tb_user_messages_recap.Edition,
tb_user_messages_recap.Etat,
tb_user.NIC_Handle,
tb_user.Pseudo

FROM tb_user_messages_recap

LEFT JOIN tb_user

ON tb_user_messages_recap.Auteur = tb_user.Pseudo

WHERE tb_user_messages_recap.Auteur='".$_SESSION_PSEUDO."' OR 
      tb_user_messages_recap.Intervenant='".$_SESSION_PSEUDO."' 

ORDER BY Edition DESC
");
    while($data=$MyPDO->fetch(PDO::FETCH_ASSOC))
    {
?>

<?php echo $data["NIC_Handle"]." - ".$data["Auteur"]; ?>
<?php echo $data["NIC_Handle"]." - ".$data["Intervenant"]; ?>
<?php echo $data["NIC_Handle"]." - ".$data["Intervenant"]; ?>

<?php }}catch(PDOException $e){echo "<div class='alert alert-danger'>".$e->getMessage()."</div>";} ?>

Thank you for your help,

Cordialy

2
  • 1
    So....what's wrong with your current query? If you want us to help, do tell what's wrong with the current query?, what do you want to get?
    – Eric
    Commented Sep 24, 2018 at 22:16
  • The logic said that you need INNER JOIN instead of LEFT JOIN.
    – Akina
    Commented Sep 25, 2018 at 4:54

1 Answer 1

0

Change the join condition to:

ON tb_user_messages_recap.Auteur = tb_user.Pseudo OR
   tb_user_messages_recap.Intervenant= tb_user.Pseudo

But really why not:

SELECT NIC_Handle
FROM tb_user
WHERE Pseudo =$_SESSION_PSEUDO

I could be wrong. Question is a bit ambiguous.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.