PHPif. elseif. else

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.