dimanche 25 août 2019

I want to show accept button if members are not friends in table

I'm trying on friend system in php. I want to show different buttons like "send request", "accept request" and "delete request" and "unfriend". I want if users (request sender and receiver) are already friends then, they have to see "unfriend" button, otherwise "send request" and if request in pending "cancle friend request".

Codes on which i'm working.

               

 <div class="col-sm-12 col-md-12 col-lg-3 user_prof_todo">
                      <div class="relation_button mt-2">
                      
                      <?php
                          $ifFrnd = "SELECT * FROM friend_request WHERE relation = 'friends'";
                            $ifFrnd_run = mysqli_query($con, $ifFrnd);
                            $ifFrnd_result = mysqli_num_rows($ifFrnd_run);
                            
                          
                          if(empty($ifFrnd_result)){?>
                              
                              <form action="" method="post">
                              <button class="btn btn-success btn-sm" name="accept_frnd_request">Unfriend</button>
                              <!-- <button class="btn btn-danger btn-sm" name="delete_frnd_request">Delete request</button> -->
                              </form>
                              <?php
                          }else {
                          
                          $check = "SELECT * FROM friend_request WHERE sender = '".$_GET['id']."' AND receiver = '".$_SESSION['id']."'";
                            $check_run = mysqli_query($con, $check);
                            $check_result = mysqli_num_rows($check_run);
                          
                          if(empty($check_result)){?>
                             
                             
                          
                         <form action="" method="post">
                              <?php
                            $frnd_check = "SELECT * FROM friend_request WHERE sender = '".$_SESSION['id']."' AND receiver = '".$_GET['id']."'";
                            $frnd_check_run = mysqli_query($con, $frnd_check);
                            $result = mysqli_num_rows($frnd_check_run);

                             if(!empty($result)){?>
                              <button class="btn btn-danger btn-sm" name="cancel_frnd_request">Cancel friend request</button>
                            <?php } else{?>
                              <button class="btn btn-success btn-sm" name="send_frnd_request">Send friend request</button>
                            <?php }?>
                         </form>
                            <?php
                             
                              } else {?>
                              <form action="" method="post">
                              <button class="btn btn-success btn-sm" name="accept_frnd_request">Accept request</button>
                              <button class="btn btn-danger btn-sm" name="delete_frnd_request">Delete request</button>
                              </form>
                              <?php }?>
                      
                        <div class="col-md-12 text-center">
                                                        <?php
                                                                if(isset($message)){
                                                                        echo "<span class='text-success'><i class='fas fa-check'></i> $message</span>";
                                                                }
                                                        ?>
                        </div>
                        <?php }?>
                      </div>
                      
                </div>

Aucun commentaire:

Enregistrer un commentaire