Ask a question about PHP assignment judgment

Source: Internet
Author: User
Ask a question about PHP assignment judgment
Just contact PHP, in a MySQL class to see such a sentence
$condition = $condition? ' WHERE '. $condition: NULL
Not too clear what meaning, ask you can explain.
I personally interpret him as: "where". $condition is empty, then the ' where '. $condition assigned to $condition, on the contrary, the $condition= $condition, do not know is right or wrong, but also hope that the great God come to teach!!

------Solution--------------------
Damn, upstairs is wrong!

If the ' where ' $condition is empty, the ' where ' $condition is assigned to $condition, whereas the $condition= $condition

=

If the $condition is not empty, the ' where ' $condition assigned to $condition, whereas the $condition=null
------Solution--------------------
This is the flattening of an SQL statement.
For example, if the user does not set a match condition, then it is
SELECT * FROM TableName;
If there is a set condition, that is, $condition is not empty.
SELECT * FROM TableName WHERE $condition;
------Solution--------------------
$a? $b: $c
PHP's ternary operator.
If $ A is true, the value of the expression is $b, and if False, the expression value is $c.
------Solution--------------------
PHP Code
$condition = $condition? ' WHERE '. $condition: null//is equivalent to if ($condition) {  $condition = ' where '. $condition;} else{  $condition = NULL;}
  • 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.