检查表中是否存在用户


Check if user is exist in the table

我有一个表名articles_likes,有3列

id   user   article
1    73      23
2    76      43
3    75      35
4    73      41

然后用户登录到系统,例如使用

$_SESSION['user_id'] = 73

我如何检查用户73是否已经存在并且已经喜欢该表中的文章?有人能帮我解决这个问题吗?非常感谢

假设您想在php中使用mysqli,那么您的查询应该如下所示:

$sql="SELECT article 
      FROM table 
      WHERE user= '".mysqli_real_escape_string($conn,$_SESSION['Username'])."'";
$result = mysqli_query($conn, $sql);

现在只需获取$result并检查它是否具有article_number