how to avoid being shown twice?

0

I have a user system in which I send a request (who sends) so that the other user (who receives it) responds.When.I do the sending the button that said "Add" changes to "Request sent" The problem is that when I enter the profile or better said entry with the account of the user to whom I send the request and search through the search engine to the user who sent me the request the button says the same, I mean, "request sent". I do so that the button says "Accept request". The button I printed with an 'echo'. I do not know what else to do. I'm somewhat limited in PHP.

Table people (users)

   -------  --------   -----------     ---------      --------   -------
   Id        Nombre     Apellidos      Correo      Password    Foto
   --------   ---------   ---------      --------    --------    -------
   5          Luis       Tavarez          @          ****      .jpg
   6          Jose       Martinez         @          ****      .jpg

Relationship / friends table

       ------------  --------   -----------     --------
          Id        User_one    User_two        Activo
        ----------   ---------   ---------      --------
           1            5          6               0

This is my code:

<?php

 include_once('conexion.php');

 if ($user != $my_id) {

 $mysqli = mysqli_connect("localhost", "root", "", "registros");
 $quer = mysqli_query($mysqli,"SELECT * FROM friends WHERE (User_one =  
'$my_id'  AND User_two = '$user') OR (User_one = '$user' AND User_two =
 '$my_id')");

   if (mysqli_num_rows($quer) > 0) 

     {

          while ($nada = mysqli_fetch_assoc($quer)) {

             if ($nada['Activo'] == 1) {


             $mensaje = "<div class='dropdownx'><button type='button' 
             onclick='myFunction()' class='dropbtnx'><i class='fa fa-thumbs-
             o-up' aria-hidden='true'></i>Amigos<i class='fa fa-caret-down' 
             aria-hidden='true'></i></button><div id='myDropdownx' 
             class='dropdowncontentx'>
             <a href='#'>Dejar de ser amigos.</a>
             <a href='#about'>About</a>

             </div></div>";

        }




              elseif ($nada['Activo'] == 0)
               {

              $mensaje = "<div class='dropdownx'><button type='button' 
              onclick='myFunction()' class='dropbtnx'>Solicitud enviada<i 
              class='fa fa-caret-down' aria-hidden='true'></i></button><div
              id='myDropdownx' class='dropdowncontentx'>
             <a href='#'>Cancelar Solicitud</a>
              <a href='#about'>About</a>

            </div></div>";
        }


       }

       }




    else { // if the relationship don't exist

        $mensaje = "<div class='dropdownx'><button type='button' 
        onclick='guardar(".$user.")' class='dropbtnx'><i class=' fa fa-plus'
          aria-hidden='true'></i>Agregar</button></div>";
         }






      }


     ?>
    
asked by luis 09.11.2016 в 02:47
source

1 answer

1

The key is in the elseif

// No relación aun, pero yo soy user_one
elseif ($nada['Activo'] == 0 and $nada['user_one'] == $my_id){

   // Muestro boton aceptar solicitud si yo soy quien recibe}

} elseif ($nada['Activo'] == 0 and $nada['user_one'] == $my_id){

   // Muestro boton de solicitud enviada

}

I explain: If user_one is the one who sends the request, it only validates if in the session you are user_one and if so, continue showing "request sent";

but if user_one is the one who receives the request, you place the "Accept request".

If I did not understand, please comment.

Note: You could split the code and create a function that serves to identify the user if it is user_one or user_two.

    
answered by 13.11.2016 в 18:56