从表中获取列值不等于零的值

从表中获取列值不等于零的值

问题描述:

i have one maildigest column in my users table so..when user logged in i keep the value in session like this

$_SESSION['maildigest'] = $user->maildigest; 

so what happened is for some particular records this column value is zero..and some particular records this column value is there like 143,113

so i am tying to show the records where the maildigest column not equal to zero in this query

i keep the session value in one variable

$parentclientadmin=$_SESSION['maildigest'];

$retval = "SELECT * FROM `mdl_user`  where  maildigest IN ($id,$parentclientadmin) and trackforums='1' "; 

can anyone help me i want to get records where maildigest not equal to zero

thanks in advance...

我的用户表中有一个maildigest列,所以当用户登录时我将值保存在会话中 p>

  $ _ SESSION ['maildigest'] = $ user-> maildigest;  
  code>  pre> 
 
 

所以发生的事情是某些特定的记录,这个列的值是零......还有一些特殊记录,这个列的值就像143,113 p> \ n

所以我想在这个查询中显示maildigest列不等于零的记录 p>

我将会话值保存在一个变量中 p>

  $ parentclientadmin = $ _ SESSION ['maildigest']; 
 
 $ retval =“SELECT * FROM`mdl_user`其中maildigest IN($ id,$ parentclientadmin)和trackforums ='1'”;  
  code>  pre> 
 
 

任何人都可以帮助我,我想获得maildigest不等于零的记录 p>

提前感谢... div>

You can use != there:-

$retval = "SELECT * FROM `mdl_user`  WHERE  maildigest IN ($id,$parentclientadmin) AND trackforums='1' AND maildigest !=0";

NOTE:- try to use preparedstatements to prevent from SQL Injection.

I would suggest to use Prepared Statement instead and your SQL should be

SELECT * FROM `mdl_user`  where  trackforums='1' and maildigest != ?";

i think you could do it this way

$retval = "SELECT * FROM `mdl_user`  where  maildigest!=0 ";

Using <> instead of !=

$retval = "SELECT * FROM `mdl_user`  where  maildigest <> 0 ";

<> is the variant present in the SQL ISO standard.