Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Avoid duplication in an array

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #36317
    nisalperifb
    Member

    I have a mysqli_query which selects user_ids from a table called comments and enters into a table named notifications. The problem is when the same user comments on the same post several time. Is there any way to check whether the user_id already exist inside the array.
    Here’s the code:

    if(isset($_POST)){
    //when save button is clicked
    $user_id=$_COOKIE;
    $content=$_POST;
    //Inserting the comments into the database
    $query_comment="INSERT INTO comments(user_id,item_id,date,comment) VALUES('$user_id','$item_id',NOW(),'$content')";
    mysqli_query($dbc,$query_comment)or die("Error in querying");

    //Inserting notifications into the database
    $query_not_id="SELECT user_id FROM comments WHERE item_id='$item_id'";
    $results_not_id=mysqli_query($dbc,$query_not_id);
    $current_user=$_COOKIE;
    //Grabbing the id of the user who created the item
    while($row_not_id=mysqli_fetch_array($results_not_id)){
    array_unique($row_not_id);
    //Inserting notifications into the table
    $not_user_id= $row_not_id;
    $query_not="INSERT INTO notifications(item_id,user_id,creater_id,not_user_id,item_type)VALUES('$item_id','$current_user','$post_creater','$not_user_id','$not_type')";
    //Stop entering the notification on the profile of the commenter
    if($not_user_id!=$current_user){
    mysqli_query($dbc,$query_not)or die("ERROR in querying notifications");
    };
    };
    mysqli_close($dbc);
    };
    #95433
    nisalperifb
    Member

    Need help soon.

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘Back End’ is closed to new topics and replies.