PHP If. Elseif.else related issues

Source: Internet
Author: User
PHP if: Elseif...else problems
This post was last edited by xytianshiwx on 2013-12-08 10:09:44

    
$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, ",")) {//Determine existence ","
$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)) {//Determine where
$sql _param_list["where"] = $param;

}elseif (Preg_match ("/\b (order|limit|group|) \b/i ", $param, $param _name)) {//Judgment 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 not assigned a $sql_param_list["field"??
Logic error or other error, please expert pointing pointing!!!

Share to: more


------Solution--------------------
Array
(
[WHERE] = name>10
)
Why is $param assigned to $sql _param_list["field"?
Your $param is "name>10" and there's No ","
only if (Preg_match ("/\b (". $where _field. ") \b/i ", $param)
------Solution--------------------
Preg_match ("/(>
------Solution--------------------
>
------Solution--------------------
=)/I ", $param)) {//
Branch can enter
------Solution--------------------
}elseif (Preg_match ("/\b (Order
------Solution--------------------
Limit
------Solution--------------------
Group
------Solution--------------------
) \b/i ", $param, $param _name)) {//Judgment order
------Solution--------------------
Limit
------Solution--------------------
Group
==> "/\b (Order
------Solution--------------------
Limit
------Solution--------------------
Group) \b/i ", //regular more than one or


------Solution--------------------
if (False!==strpos ($param, ",")) {//Determine existence ","
That would be even more wrong, a single name would not have "," the

According to the grammar paradigm of SQL instruction
You should read the substring separated by a space character, and determine which grammatical component it belongs to.
And each section of the SQL instruction is 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.