A
A
Andrey Kolesnik2020-10-02 22:45:00
PHP
Andrey Kolesnik, 2020-10-02 22:45:00

Outputting individual sql dialogs?

There is a table 'message' (photo below)
What needs to be done is to display a dialog with a dialog column column:
sender id, recipient id.
Here is my output code.
but WHERE doesn't work..

<?php
require_once 'core/connect.php';
$to = $_GET['sel'];
$sender = $_SESSION['user']['id'];
$query = mysqli_query($connect, 
"SELECT
m.id_sms, m.dialog, u.name as id_sender, m.message, m.id_recipient, m.time
FROM messages m 
LEFT JOIN users u ON m.id_sender = u.id WHERE dialog = '$sender,$to' OR '$to,$sender'
ORDER BY m.time ASC

");
while ($result = mysqli_fetch_array($query)) {
echo 
'
html..
'; 
}
?>

5f7783053c46b201330314.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2020-10-02
@chikada3301

Your table is not designed correctly. To solve the problem, the dialog field is not needed, it is enough to set the condition WHERE id_sender = $sender AND id_recipient = $to.

A
Andrey Kolesnik, 2020-10-02
@chikada3301

Replace with
WHERE dialog = '$sender,$to' OR '$to,$sender'

WHERE id_sender = $sender AND id_recipient = $to OR id_sender = $to AND id_recipient = $sender

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question