I am confused, younger brother.

Source: Internet
Author: User
A simple question puzzles me for a long time $ nian = 1990; $ a = ($ nian-1); $ B = ($ nian + 1); $ query = & quot; SELECT * FROM 'final' WHERE 'writedate' & lt; '$ B' and 'a simple question that puzzles me for a long time
$ Nian = 1990;
$ A = ($ nian-1 );
$ B = ($ nian + 1 );
$ Query = "SELECT * FROM 'final' WHERE 'writedate' <'$ B' and 'writedate'> '$ '";
$ Result = mysql_query ("$ query ");
$ Row = mysql_fetch_array ($ result );

Print_r ($ row );
In this case, the correct result is output. in this case, nothing is output every time.
$ Nian = 1990;
$ Query = "SELECT * FROM 'final' WHERE 'writedate' <'($ nian + 1)' and 'writedate'> '($ nian-1 )'";
$ Result = mysql_query ("$ query ");
$ Row = mysql_fetch_array ($ result );
Print_r (row );
Writedate is the date type, but there were similar cases before, the previous field is tinyint type, the problem is to store one more variable, such as the above $ a = ($ nian-1 ); what is the difference between addition and subtraction, such as $ nian-1?



------ Solution --------------------
'Writedate' <'($ nian + 1 )'
'($ Nian + 1)' is a string. how can this operation be performed?

------ Solution --------------------
$ Query = "SELECT * FROM 'final' WHERE 'writedate' <'($ nian + 1)' and 'writedate'> '($ nian-1 )'";
In this way, writing ($ nian + 1) will not be parsed.

------ Solution --------------------
The SQL statement is... 1990 + 1... 1990-1 ...... Instead of the expected 1991 million, you should think about it carefully.
------ Solution --------------------
Supplement:

'Where' writedate' <'($ nian + 1)' and 'writedate'> '($ nian-1 )'";

If so, 'where' writedate' <($ nian + 1) and 'writedate'> ($ nian-1) "; is expected

The extra ''will be treated as the overall string, together with parentheses,
------ Solution --------------------
Reduce the number of operations in SQL statements as much as possible.
PHP code
$ Query = "SELECT * FROM 'final' WHERE 'writedate' <'". ($ nian + 1 ). "'and 'writedate'> '". ($ nian-1 ). "'";
------ Solution --------------------
Discussion

It turns out that MYSQL cannot be converted. it's speechless, but it's okay. it's just a bit difficult to get things out, so I don't need to get it. thanks for referencing:
The SQL statement is... 1990 + 1... 1990-1 ...... Instead of the expected 1991 million, you should think about it carefully.

------ Solution --------------------
Discussion

Why? I seem to see the reference in brackets often used in books:
$ Query = "SELECT * FROM 'final' WHERE 'writedate' <'($ nian + 1)' and 'writedate'> '($ nian-1 )'";
In this way, writing ($ nian + 1) will not be parsed.

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.