[英]Unknown Column In Where Clause (as)
SET @value = '';
SELECT
id, order_kind, property_kind, town, images, agreement, uprice, eprice,
tprice, pprice, bprice, qprice, status, createtime, town_title, fullname,
mobile, profile_image, area, barea, address,
CONCAT(id+9000) AS sid,
CONCAT(area,' m') AS marea,
CONCAT(barea,' m') AS mbarea
FROM `sells`
WHERE `order_kind` = '$order_kind'
AND `property_kind` = '$property_kind'
AND (
sid LIKE CONCAT('%', @value, '%') ||
town_title LIKE CONCAT('%', @value, '%') ||
fullname LIKE CONCAT('%', @value, '%') ||
mobile LIKE CONCAT('%', @value, '%') ||
marea LIKE CONCAT('%', @value, '%') ||
mbarea LIKE CONCAT('%', @value, '%') ||
address LIKE CONCAT('%', @value, '%')
)
I use this sql for searching, and erroring unknown column 'sid' in where clause我使用这个 sql 在 where 子句中搜索和错误未知列“sid”
i change where to having but not work php loop我将位置更改为拥有但不工作 php 循环
Your query defines sid
as CONCAT(id+9000) AS sid
in the SELECT
clause.您的查询在
SELECT
子句中将sid
定义为CONCAT(id+9000) AS sid
。 You can't reuse that alias in the WHERE
clause.您不能在
WHERE
子句中重复使用该别名。 Instead, you need to repeat the expression.相反,您需要重复该表达式。
So basically change this condition:所以基本上改变这个条件:
sid LIKE CONCAT('%', @value, '%')
To:到:
CONCAT(id+9000) LIKE CONCAT('%', @value, '%')
Important note: use prepared statements: Do not concatenate PHP variables in the query string.重要说明:使用准备好的语句:不要在查询字符串中连接 PHP 个变量。 this is both inefficient and unsafe: Recommended reading: How can I prevent SQL injection in PHP?
这既低效又不安全:推荐阅读: How can I prevent SQL injection in PHP?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.