Select Multiple DISTINCT di PHP PDO?

Salam kenal bang, bang maaf mau tanya w baru belajar php dan kseulitan untuk nampilin data pakai fungsi DISTINCT, jadi di kode ini pengennya kaya pesan whatsapp gitu, jika user_security => ada di id_send atau id_receiver, di tampilkan hanya sekali, 

<?php try {
$show_index        = "SELECT DISTINCT IF (id_send = '$user_security', id_receiver, id_send) AS id_send 
                    FROM dUfA1_message WHERE '$user_security' IN (id_receiver, id_send) ORDER BY id DESC";

$show_index1       = $pdo->prepare($show_index);
$show_index1       ->execute(); } 
catch (PDOException $exception) {
    echo "ada kesalahan pada query : ".$exception->getMessage();
}
while ($data_message  = $show_index1->fetch(PDO::FETCH_ASSOC)) {  
$security             = $data_message['security'];
$id_send              = $data_message['id_send'];
$id_receiver          = $data_message['id_receiver'];
$message              = $data_message['security'];
$message_dcreate      = $data_message['dcreate'];
$message_date         = get_time_ago(strtotime("$message_dcreate"));


if ($user_security == $id_send) {$sc_master = $id_receiver;}
else {$sc_master = $id_send;}

echo "

<div class='section margintop15'>
    <div class='container'>
        <div class='col-12'>
            <div class='row'>
                <div class='col-9 paddingleft0 margintop5'>
                    <div>
                        <b>$sc_master</b>
                        <span class='float-right text-secondary font9'>$message_date</span>
                    </div>
                    <div class='font10'>
                        $message
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
";}?>

Mohon bantuannya bang
avatar diki

Ditanyakan oleh @diki

1 Kontribusi 0 Poin

Login untuk menanggapi


Jawaban

Belum ada Jawaban, jadi yang pertama

Login untuk gabung berdiskusi