@oceweb ciao e buona domenica sono riuscito a eliminare la chat ora sia l'utente A e B possono eliminare la chat ma la conversazione la può eliminare solo chi invia o chi riceve non riesco a capire cosa manca posto i codici ```
<?php
function getConversation($user_id, $conn){
/**
Getting all the conversations
for current (logged in) user
**/
$sql = "SELECT * FROM conversations
WHERE user_1=? OR user_2=?
ORDER BY conversation_id DESC";
$stmt = $conn->prepare($sql);
$stmt->execute([$user_id, $user_id]);
if($stmt->rowCount() > 0){
$conversations = $stmt->fetchAll();
/**
creating empty array to
store the user conversation
**/
$user_data = [];
# looping through the conversations
foreach($conversations as $conversation){
# if conversations user_1 row equal to user_id
if ($conversation['user_1'] == $user_id) {
$sql2 = "SELECT *
FROM users WHERE user_id=?";
$stmt2 = $conn->prepare($sql2);
$stmt2->execute([$conversation['user_2']]);
}else {
$sql2 = "SELECT *
FROM users WHERE user_id=?";
$stmt2 = $conn->prepare($sql2);
$stmt2->execute([$conversation['user_1']]);
}
$allConversations = $stmt2->fetchAll();
# pushing the data into the array
array_push($user_data, $allConversations[0]);
}
return $user_data;
}else {
$conversations = [];
return $conversations;
}
}
---------------------------
<ul id="chatList"
class="list-group mvh-50 overflow-auto">
<?php if (!empty($conversations)) { ?>
<?php
foreach ($conversations as $conversation){ ?>
<li class="list-group-item">
<a href="chat.php?user=<?=$conversation['username']?>"
class="d-flex
justify-content-between
align-items-center p-2">
<div class="d-flex
align-items-center">
<img src="uploads/<?=$conversation['p_p']?>"
class="w-10 rounded-circle">
<h3 class="fs-xs m-2">
<?=$conversation['name']?><br>
<small>
<?php
echo lastChat($_SESSION['user_id'], $conversation['user_id'], $conn);
?>
</small>
</h3>
</div>
<?php if (last_seen($conversation['last_seen']) == "Active") { ?>
<div title="online">
<div class="online"></div>
</div>
<?php } ?>
</a>
<a href="deleteconv.php?user_2=<?=$conversation['user_id']?>" class="btn btn-danger"><i class="fa fa-trash-o"></i> Elimina messaggi</a>
</li>