[英]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.