I am working with principle 2 and I have come up with a situation in which I only have some questions Want to type user?
Type Status Active UserA 0 UserB 0 1 User C 1 1 UserD 1 0
All the questions I want to do is User A, User C and User D. One example is the next query:
public function countMonth () {$ date = new \ Datetime ('now'); $ NewDate = $ date- & gt; Format ('Y-M'); $ This- & gt; Qb = $ this- & gt; Em- & gt; CreateQueryBuilder (); ('U.creation_date like? 1') - (- '' model 'user', 'u') - & gt; From (- '-' like-> qb-> Select (Calculate as' Cant (U) '- - - gt; - & gt; and where (' u.status & lt; & gt; ; 0 and u.active & lt;> 1 '); // user b $ this-> qb- & gt; set parameter (1, "$ newDate%"); $ query = $ this- & gt; ; Qb- & gt; getQuery (); Return $ query-> getSingleScalarResult ();}
I want to know how to do a query that throws me back all the users But user B. Because what I wrote only gives me access.
I know that I have to do all this. I can get these users but UsersB, but it allows me to type in two lines of code to ask in such a way. Is there any more simple way?
Public function countMonth ) {$ Or x = $ this->;;;;;;;;; expr () - & gt; orX (); $ and X = $ it-> qb-> expr () - & gt; And X (); $ Date = new \ Datetime ('now'); $ NewDate = $ date- & gt; Format ('Y-M'); $ this-> qb = $ this-> - & gt; createQueryBuilder (); $ The-> gtc-> gt; Choose (Cant 'count as' U') - & gt; From ('Model \ User', 'U'); $ And X-> Add (like 'u.creation_date? 1'); $ Or X- & gt; Plus ('u.status = 1 and u.active = 1 or u.active = 0'); $ Or x-> add ('u.status = 0 and u.active = 0'); $ AndX-> (OrX $); $ This- & gt; Qb-> Add ('ou', $ and x); $ This- & gt; Qb-> SetParameter (1, "$ newDate%"); $ Query = $ this- & gt; Qb-> GetQuery (); Return $ query- & gt; GetSingleScalarResult (); }
You must use OR
.status & lt; & Gt; 0 or u.active & lt; & Gt; 1 '
-
' u.status & lt; & Gt; Logic output for 0 and U.active & lt; & Gt; true only for userD for both logic arguments when using and Logical Operators Li. > This condition fails for userA U.Status <0.
is true and- userC for u.active & lt;> 1 fails in this situation.
Now you get following using or :
- For userA : < Code> U. Status & lt; & Gt; 0
u.active & lt; & Gt; userB :
u.status
is incorrect and> 0 u.active & lt; & Gt; << Strong> userC for
is true andu.status
0u.active & lt; & Gt;
is incorrect andu.status
0userD & Gt; u.active & lt; & Gt; 1
true, is a true , pass - userC for u.active & lt;> 1 fails in this situation.
this way, passes all the rows but the userB condition .
--------- Edit -----------
Check it
Comments
Post a Comment