Thinkphp using an expression in a Where condition

Source: Internet
Author: User
Tags comparison table

Https://www.jiloc.com/43040.html

We introduced the thinkphp view template using an example summary, below we summarize the MySQL database query thinkphp in the WHERE condition expression.

The Where condition expression format is:

<textarea class="crayon-plain print-no" style="font-size: 12px !important; line-height: 15px !important; z-index: 0; opacity: 0; overflow: hidden" readonly="" data-settings="dblclick">$map [' field name '] = Array (' expression ', ' operating condition ');</textarea>
1 $Map[' field name '] = array(' expression ', ' operating condition ');

Where $map is an ordinary array variable that can be named according to your needs. The expression in the above format is actually the meaning of the operator:

thinkphp operator and SQL operator comparison table
TP operator SQL operator Example actual query conditions
eq = $map [' id '] = array (' eq ', 100); Equivalent to: $map [' id '] = 100;
Neq != $map [' id '] = array (' NEQ ', 100); ID! = 100
Gt > $map [' id '] = array (' GT ', 100); ID > 100
Egt >= $map [' id '] = array (' EGT ', 100); ID >= 100
Lt < $map [' id '] = array (' lt ', 100); ID < 100
Elt <= $map [' id '] = array (' ELT ', 100); ID <= 100
Like Like $map < ' username ' > = array (' Like ', ' admin% '); Username like ' admin% '
Between Between and $map [' id '] = array (' Between ', ' 1,8′ '); ID between 1 and 8
Not between Not between and $map [' id '] = array (' Not between ', ' 1,8′ '); ID not between 1 and 8
Inch Inch $map [' id '] = array (' In ', ' 1,5,8′ '); ID in (1,5,8)
Not in Not in $map [' id '] = array (' Not ', ' 1,5,8′ '); ID not in (1,5,8)
and (default) and $map [' id '] = Array (array (' GT ', 1), Array (' LT ', 10)); (ID > 1) and (ID < 10)
Or Or $map [' id '] = array (' GT ', 3), array (' LT ', ten), ' or '); (ID > 3) OR (ID < 10)
XOR (different OR) Xor Only one of the two inputs is true, the result is true, otherwise false, the example is slightly. 1 XOR 1 = 0
Exp Synthetic expressions $map [' id '] = Array (' exp ', ' in (1,3,8) '); $map [' id '] = array (' In ', ' 1,3,8′ ');
Additional Information
  • Like SQL, the thinkphp operator is case-insensitive and EQ is the same as EQ.
  • Between, in conditions support strings or arrays, that is, the following two formulations are equivalent:
    <textarea class="crayon-plain print-no" style="font-size: 12px !important; line-height: 15px !important; z-index: 0; opacity: 0; overflow: hidden" readonly="" data-settings="dblclick">$map [' id '] = array (' Not in ', ' 1,5,8 '); $map [' id '] = Array (' No in ', Array (' 1 ', ' 5 ', ' 8 '));</textarea>
    12 $map[ ' id ' ]  = array ( ' not in ' , ' 1,5,8 ' ) $Map[' id '] = array (' not ' ,array(' 1 ', ' 5 ',' 8 ');
Exp-expression

The exp in the previous table is not an operator, but rather a synthetic expression to support more complex conditional settings. EXP's operating conditions are not treated as strings and can be used with any SQL-supported syntax, including the use of functions and field names.

EXP is not only used for where conditions, but also for data updates, such as:

<textarea class="crayon-plain print-no" style="font-size: 12px !important; line-height: 15px !important; z-index: 0; opacity: 0; overflow: hidden" readonly="" data-settings="dblclick">$Dao = M ("article");//Build the data array of Save, the article hits the number +1$data[' id ') = ten, $data [' counter '] = Array (' exp ', ' counter+1 ');// Save modified Data $user->save ($DATA) according to the conditions;</textarea>
12345678 $Dao = M("article"); //Build data array for Save, article hits +1$Data[' id '] = ten; $Data[' counter '] = array(' exp ',' counter+1 ' );//Save modified data according to the conditions$User,save($data);

Thinkphp using an expression in a Where condition

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.