gpt4 book ai didi

mysql - WHERE CURDATE() < end_date AND WHERE title LIKE '%test%'

转载 作者:行者123 更新时间:2023-11-29 11:37:25 24 4
gpt4 key购买 nike

我正在构建新闻网站。

我试图只打印正确的 end_date 内的新闻,但有些我无法让它工作

$sql2 = "SELECT * FROM p_news WHERE CURDATE() < end_date AND WHERE title LIKE '%$search%'";

当我尝试回显 SQL 并在 phpmyadmin 中测试它时

出现这个错误

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE title LIKE '%test%' LIMIT 0, 30' at line 1

最佳答案

都是documented :

SELECT
[ALL | DISTINCT | DISTINCTROW ]
[HIGH_PRIORITY]
[MAX_STATEMENT_TIME = N]
[STRAIGHT_JOIN]
[SQL_SMALL_RESULT] [SQL_BIG_RESULT] [SQL_BUFFER_RESULT]
[SQL_CACHE | SQL_NO_CACHE] [SQL_CALC_FOUND_ROWS]
select_expr [, select_expr ...]
[FROM table_references
[PARTITION partition_list]
[WHERE where_condition]
[GROUP BY {col_name | expr | position}
[ASC | DESC], ... [WITH ROLLUP]]
[HAVING where_condition]
[ORDER BY {col_name | expr | position}
[ASC | DESC], ...]
[LIMIT {[offset,] row_count | row_count OFFSET offset}]
[PROCEDURE procedure_name(argument_list)]
[INTO OUTFILE 'file_name'
[CHARACTER SET charset_name]
export_options
| INTO DUMPFILE 'file_name'
| INTO var_name [, var_name]]
[FOR UPDATE | LOCK IN SHARE MODE]]

换句话说,您可以有零个或一个 WHERE,但不能有两个。

还有:

The WHERE clause, if given, indicates the condition or conditions that rows must satisfy to be selected. where_condition is an expression that evaluates to true for each row to be selected. The statement selects all rows if there is no WHERE clause.

In the WHERE expression, you can use any of the functions and operators that MySQL supports, except for aggregate (summary) functions. See Section 9.5, “Expression Syntax”, and Chapter 12, Functions and Operators.

关于mysql - WHERE CURDATE() < end_date AND WHERE title LIKE '%test%',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36354117/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com