If there is and OR, an SQL statement is generated based on several fields, such as data table information. how can I combine them into an SQL statement? If all is and or all is or, this method is easy to handle, but both are available at the same time, what should we do? PHPcode $ SQL & quot; select * fromsk_cvfilterwherecvid58andcolu generate an SQL statement based on several fields if they are all AND OR
Is there any good way to combine data table information into an SQL statement? If all is and or all is or, this method is easy to handle, but both are available at the same time, what should we do?
All are and or.
PHP code
$sql = "select * from sk_cvfilter where cvid=58 and columnname!=''"; $query = mysql_query($sql); $sql = ''; while($row = mysql_fetch_assoc($query)){ if($row['comparator']=='eq'){$comparator="=";} else{$comparator=$row['comparator'];} $sql .=$row['columnname'].$comparator."'".$row['value']."' ".$row['andor'].' '; }
------ Solution --------------------
SQL code
Select * from sk_cvfilter where cvid = 58 and columnname! = ''And andor = 'and' or andor = 'OR'
------ Solution --------------------
Why is there a problem with your record?
For example, if a (a = 1 or (B = 2 and B = 3) appears, how do you record it?
I guess so.
Columnname comparator value andor
A eq 1 or
B eq 2 and
C eq 3
This problem occurs. if you do not know the above relation (a = 1 or (B = 2 and B = 3 )),
If you only look at the structure, you think
(A = 1 or B = 2) and B = 3
Or
A = 1 or (B = 2 and B = 3)
All or statements for one condition and other conditions and are not considered.
PHP code
------ Solution --------------------
PHP code