Answer the question
In order to leave comments, you need to log in
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..
';
}
?>
Answer the question
In order to leave comments, you need to log in
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
.
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 questionAsk a Question
731 491 924 answers to any question