PHPif .. elseif... else question this post was last edited by xytianshiwx from 2013-12-0810: 09: 44 & nbsp; & lt ;? Php & nbsp; $ field_funcCOUNT | AVG | FIRST | LAST | MAX | MIN | SUM | TOP; & nbsp; $ whe PHP if... elseif... else
This post was last edited by xytianshiwx at 10:09:44, January 8 ,.
$ Field_func = "COUNT | AVG | FIRST | LAST | MAX | MIN | SUM | TOP ";
$ Where_field = "Where | or | xor | and | in ";
$ Param = "name ";
$ SQL _param_list = array ();
If (false! = Strpos ($ param, ",") {// determines whether "," exists.
$ SQL _param_list ["field"] = $ param;
} Else {
If (preg_match ("/\ B (". strtolower ($ field_func ). ") \ B \ (\ * | [a-zA-Z _ ']) + \)/I", $ param )){
$ SQL _param_list ["field"] = $ param;
} Elseif (preg_match ("/\ B (". $ where_field. ") \ B/I", $ param) | preg_match ("/(>|>|=)/I", $ param) {// judge where
$ SQL _param_list ["where"] = $ param;
} Elseif (preg_match ("/\ B (order | limit | group |) \ B/I", $ param, $ param_name) {// judge order | limit | group
Switch ($ param_name [0]) {
Case "order": $ SQL _param_list ["order"] = $ param;
Break;
Case "limit": $ SQL _param_list ["limit"] = $ param;
Break;
Case "group": $ SQL _param_list ["group"] = $ param;
Break;
}
} Else {
$ SQL _param_list ["field"] = $ param;
}
}
Print_r ($ SQL _param_list );
$ Param is not assigned $ SQL _param_list ["field"]?
Logic errors or other errors !!!
Share: More
------ Solution --------------------
Array
(
[Where] => name> 10
)
Why is $ param assigned to $ SQL _param_list ["field"]?
Your $ param is "name> 10" without ","
Only if (preg_match ("/\ B (". $ where_field. ") \ B/I", $ param)
------ Solution --------------------
Preg_match ("/(>
------ Solution --------------------
>
------ Solution --------------------
=)/I ", $ param )){//
Branches can enter
------ Solution --------------------
} Elseif (preg_match ("/\ B (order
------ Solution --------------------
Limit
------ Solution --------------------
Group
------ Solution --------------------
) \ B/I ", $ param, $ param_name) {// judge order
------ Solution --------------------
Limit
------ Solution --------------------
Group
==> "/\ B (order
------ Solution --------------------
Limit
------ Solution --------------------
Group) \ B/I ", // There are multiple or
------ Solution --------------------
If (false! = Strpos ($ param, ",") {// determines whether "," exists.
That's even worse. there won't be "," for a single name.
Follow the syntax paradigm of SQL commands
You should read substrings separated by space characters to determine which syntax component it belongs.
In addition, each section of the SQL command has a specific identifier.