Provides various official and user-released code examples. For code reference, you are welcome to exchange and learn the omnipotent single-condition query functions, such as code.
The Getx2x function has four parameters:
The first parameter [required] is the table name;
The second parameter [required] is the field name;
The third parameter [must] is the value of the queried field.
The fourth parameter [Optional] is the queried field name. If not specified, the default value is 'id '.
// Example 1:
// To query the think_user table, id = 12 Username:
$ Username = Getx2x ('user', 'username', '12 ');
// Or
$ Username = Getx2x ('user', 'username', '12', 'id ');
Note: $ u
Put the function code in Common/Common. php under the project directory.
// Universal single-condition query function, created by lisan
Function Getx2x ($ table, $ fields, $ id, $ str ){
$ Aa = M ($ table );
If (empty ($ str )){
$ Expression = 'getbyid ';
} Else {
$ Expression = 'getby'. $ str;
}
$ Thisaa = $ aa-> field ($ fields)-> $ expression ($ id );
$ Bb = explode (',', $ fields );
If (count ($ bb) <= 1 ){
Return $ thisaa [$ fields];
} Else {
Return $ thisaa;
}
}
AD: truly free, domain name + VM + enterprise mailbox = 0 RMB