简体   繁体   English

如何找出一个值是否匹配一个可能为空的列?

[英]How to find out if a value matches a possibly null column?

I am trying to write a function to determine whether or not a given value, $useremail, matches the values in a column member_email1 in a row that matches a given value $gid. 我正在尝试编写一个函数来确定给定值$ useremail是否与匹配给定值$ gid的行中member_email1列中的值匹配。 Many of the rows have empty / null values in the column member_email1, while others are filled out with emails. 许多行在member_email1列中具有空值/ null值,而其他行则用电子邮件填充。

I'd like the function to return zero unless member_email1 actually contains a value that matches $useremail. 我希望该函数返回零,除非member_email1实际上包含与$ useremail匹配的值。 However right now it seems to be returning 1 in all circumstances. 但是现在看来,在所有情况下它都将返回1。 Here is what I have so far: 这是我到目前为止的内容:

function IsInvitedToGroup($useremail, $gid){
    global $db;
    $q= "select count(*) from ! where group_id=? AND member_email1=?";
    $res= $db->getOne($q, array('member_email1', $email, $gid));
    if($res > 0) {
        return 1;
    }
    return 0;
}

How can I correct this so that it returns zero whenever $useremail does not match the value in the member_email1 column of the row corresponding to $gid? 我该如何纠正它,以便在$ useremail与$ gid对应的行的member_email1列中的值不匹配时,它返回零?

As stated, we don't see your db class, but does it work when you use the correct variable $useremail and the params are in the correct order? 如前所述,我们看不到您的db类,但是当您使用正确的变量$useremail并且params的顺序正确时,它是否起作用?

$res= $db->getOne($q, array('member_email1', $gid, $useremail));

This was all from my crystal ball. 这都是我的水晶球。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 MySQL-如何插入可能为空的值 - MySQL - How to insert a possibly null value 找出列是否在mysqli中支持“ Null”值 - Find out if the column supports “Null” values in mysqli 找出string是否匹配数组键,返回该键的值 - Find out if string matches array key, return value for that key 如何从表中第3列匹配值而第4列匹配值的表的第4列中获取值? - How to get the value from column 4 in a table where column 3 matches a value and column 4 matches a value ? 我如何找出所有可能由一段PHP代码抛出的错误? - How can I find out all the errors that can possibly be thrown by a block of PHP code? 在数据库中找到匹配的行,其中某一列与动态数组中的一个条目匹配 - Find matching rows in a database where a column matches one entry out of a dynamic array 如何从表中查找具有不同用户ID的值匹配数 - how to find the number of value matches with different user ids from the table SQL查询以选择行计数,即使变量列表中的列中至少有一个值匹配也是如此 - Sql query to select row count even when at least one value matches in column out of list of variables 找出时间段是否与当前时间匹配 - Find out if a time period matches the current time 与 request->get() 一起提供的 Psalm 可能为空值 - Psalm possibly null value provided with request->get()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM