Find an SQL query statement: select * fromTablewherABCDselect & nbsp; * & nbsp; from & nbsp; Table & nbsp; wher & nbsp; A & nbsp; and & nbsp; B & nbsp; and & nbsp; C & nbsp; and & nbsp; D find an SQL query statement: select * from Table wher A B C D
Select * from Table wher A and B and C and D
Where A, B, C, and D are the conditions. How should we construct it?
Is it necessary to first judge a, B, c, d, as long as one is not empty, then "where"
What about AND?
------ Solution --------------------
Judge whether it is not empty, spell the SQL string. generally, add where 1 = 1 First, no where and A will appear
------ Solution --------------------
Hookee () positive solution
------ Solution --------------------
Hookee () positive solution
Where 1 = 1 and where 1! = 1 is often used in SQL
1 = 1 pave the way for adding things to the back, 1! = 1 to get the table structure
------ Solution --------------------
$ AWhere [] = "1 = 1 ";
If (! Empty ($ ))
$ AWhere [] = $;
If (! Emtpy ($ B ))
$ AWhere [] = $ B;
If (! Empty ($ C ))
$ AWhere [] = $ C;
If (! Empty ($ D ))
$ AWhere [] = $ D;
$ SWhere = join ('and', $ aWhere );
$ SSql = "select * from tbl where $ sWhere order by id desc ";
------ Solution --------------------
$ Condition = "";
$ Link_symbol = "";
If ($)
{
$ Condition. = "$ link_symbol $ ";
$ Link_symbol = "and ";
}
And so on