0

In the table shown in the image,I want to show those names that the user added by clicking save, but if both are added by each other,like if Alice adds Bob and Bob has Added Alice you must indicate it (with some symbol, another color). How to make a database table for this because I'm unable to verify that if User Alice added Bob How do I confirm that Bob has also added Alice to show them in the table below. this is the image what I want to get

here is my code to do this index.php

<form action="save.php" method="post">
        <div class="text-center" id='input_tag'>
            <input type="text" name="name" id= 'input'>
            <input type="submit" name="submit" class="btn btn-dark  " id = "button" value="Save">
        </div>
    </form>
    <div class="container">
        <div class="row">

                <div class="col-md-4">
                    <table width="100"  class="table" id = 'tb'>
                        <?php 
                            $connect = mysqli_connect('localhost','root','root','user');
                            $query = "SELECT name from userdata order by id DESC";

                            $run = mysqli_query($connect,$query);


                            while($row = mysqli_fetch_array($run))
                            {

                                    echo "<tr>";
                                    echo "<td class= 'active'>".$row['name']."<td>";
                                    echo "</tr>";

                            }   



                         ?>


                    </table>
                </div>


        </div>
</div>

here is save.php

$connect = mysqli_connect('localhost', 'root' ,'root' ,'user');

if($connect){
    if(isset($_POST['submit']))
    {
        $name = $_POST['name'];
        $query = "INSERT INTO `userdata`(`name`) values ('$name')";

        if(mysqli_query($connect,$query)){
            header('location:index.php');

        }
    }

}
else{
    echo "not connected";
}

this is my table in the database table in the DB

Khan
  • 23
  • 1
  • 9
  • Has your table only one column? Wouldn't you at least have another column that states who added a certain person? Show us your data structure of Table `userdata` – Edwin Krause Nov 10 '18 at 08:18
  • If I understand your question correctly (that "added" means something like "added as a friend", and that you can "add" multiple users), this is a many-to-many-relationship, and you need a second table for it, see e.g. [Many to Many Self referencing relationship](https://stackoverflow.com/q/35783630). – Solarflare Nov 10 '18 at 08:22
  • Yeah currently it only contains id and name, nothing else, I know it should have some column that contains the state of who is adding which user.but I don't know how to do this.@EdwinKrause – Khan Nov 10 '18 at 08:24
  • it is something like: when someone logs In to my system, there is input box and the save button for the user who is now logged in , so when s/he type something and click on save s/he will "add" someone , if that guy is already added by this one who is currently logged in then show his/her name in the table with some color or symbol.How to make tables for this? – Khan Nov 10 '18 at 08:32

0 Answers0