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.