Private message system in php

2

I'm trying to make a system of private messages in PHP, at the moment I have managed to show the private messages that a user has, with the following code:

 <div>
    <?php
    require_once "messages.php";

    //obtengo todos los mensajes privados del usuario con id=3 (de prueba)
    $private= Usuarios::GetPrivate(3);

    //obtengo el usuario que escribió cada mensaje
    foreach ($private as $priv) {
       $id= $priv->emisor_id;
       $usuario = Usuarios::GetUser($id);

    //imprimo el usuario
    foreach ($usuario as $usu){
        echo $usu->user;
        echo "<br>";
        ?>

    //incluyo un botón para responder
    <input type="submit" value="<?php echo "responder a ".$usu->user ?>" name="button" id="button">

        <?php

    }
    //imprimo el mensaje
    echo $priv->message;
    echo "<br>";
    ?>

    -----------------------------------------------------
    <br><br>


</div>

I would like to know if someone could give me some indication on how to do so that the user can respond directly to a private message. The table of private messages has the fields id, message, emitter_id and receiver_id. Should I add some more field?

    
asked by kalia 07.08.2017 в 20:26
source

1 answer

0

I think you would create "themes / thread / conversation" (I will call it thread for the example) and a table N: M for user-thread or whatever you want to call it in which if they are private you only have to add them to the 2 and block the invitation to a third party.

So your table would be id, message, emitter_id, thread_id.

    
answered by 07.08.2017 в 21:15