MySql Query比较一个表中的两列值,如果条件

时间:2019-07-01 14:40:31

标签: php mysqli

我正在尝试解决以下问题:在插入前将 插入前 列值partnerCodepartnerCodeOwner1username进行比较下表中,如果partnerCode and partnerCodeOwner1的值与username相同,则会出现错误消息,并且插入操作不应完成! 比较时可能有问题吗?任何语法错误? PHP 7.0版

我的尝试低于但不正确!

  $user_check_query = "SELECT * FROM refer";
  $result = mysqli_query($db, $user_check_query);
  $user = mysqli_fetch_assoc($result);


    if ($user['username'] === $user['partnerCodeOwner1']) {
      array_push($errors, "You can't add item to yourself");
    }

    if ($user['username'] === $user['partnerCode']) {
      array_push($errors, "You can't add item to yourself");
    }


if (count($errors) ==0) {
//Start inserting
}

表中的示例

表: refer

      ID      randomfield    username      partnerCode    partnerCodeOwner1  
    +-------+ ------------+-------------+-----------------+-----------+
    |   1   | A45scdv     |  John       |  Not same       |    John   |
    +-------+-------------+-------------+-----------------+-----------+
    |   2   | das654d     | Alex        |  Alex           | Not same  |
    +-------+-------------+-------------+-----------------+-----------+

0 个答案:

没有答案