Hi all,
I have assigned a column called "friendshipstatus" as a default value =0 in addfriends table that user can add other users to it to be friends as the code bellow which will give any users added as friend in addfriendss table the "friendshipstatus" value of 1
<?php
include "Config.php";
//To check if user is existing or not in addfriends table by their id.
$id = $_GET['id'];
$sql = "SELECT * FROM addfriends WHERE id = $id";
$result = $conn->query($sql);
if($result->num_rows >= 1) {
echo '<script>alert("You Are Already Friends.")</script>';
header("Refresh:0; url=index.php");
}else{
//Then if user is not exist in the addfriends table add it by its id.
$sql = "INSERT INTO addfriends (id,fname, lname, email,reg_date,friendshipStatus)
SELECT id, fname, lname, email, reg_date,1
FROM users WHERE id = $id";
if ($conn->query($sql) === TRUE){
echo '<script>alert("You Are Friends Now.")</script>';
header("Refresh:0; url=index.php"); } else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
?>
Now I want to know how to detect when "friendshipstatus" =0 and when it =1
using mysql php
Thanks in advance