[英]Issue with SQL in php not working as expected
Hi i have two sql statements the first one is 嗨,我有两个sql语句,第一个是
$sql = "SELECT TOP 2
ReaderData.ReaderIndex,
ReaderData.CardID,
ReaderData.ReaderDate,
ReaderData.ReaderTime,
ReaderData.controllerID,
Left([dtReading],10) AS [date],
ReaderData.dtReading
FROM ReaderData
WHERE ReaderData.controllerID=$this->Id
ORDER BY ReaderData.ReaderIndex desc;";
and the second one which is 第二个是
$sql = "SELECT
[SHOP FLOOR PRODUCTION PLAN].[MACHINE],
[SHOP FLOOR PRODUCTION PLAN].[cycletime]
WHERE [SHOP FLOOR PRODUCTION PLAN].[MACHINE]=$this->name
FROM [SHOP FLOOR PRODUCTION PLAN]";
the first one works as expected however the second one does not work with the WHERE in there if i remove it then it spits out one of the enterys in the table and i am not sure why Any help would be appreciated 第一个按预期工作,但是第二个不能与WHERE一起使用,如果我将其删除,则它会吐出表中的一个小肠,我不确定为什么会有所帮助
Since I am assuming [SHOP FLOOR PRODUCTION PLAN].[MACHINE]
is a string, try putting quotes around the dynamic $this->name
part of the query. 由于我假设
[SHOP FLOOR PRODUCTION PLAN].[MACHINE]
是一个字符串,因此请尝试在查询的动态$this->name
部分周围加上引号。 eg 例如
WHERE [SHOP FLOOR PRODUCTION PLAN].[MACHINE]='$this->name' [车间生产计划]的位置。[MACHINE] ='$ this-> name'
Also, the WHERE
clause must appear after the FROM
clause: 另外,
WHERE
子句必须出现在 FROM
子句之后:
SELECT [SHOP FLOOR PRODUCTION PLAN].[MACHINE], [SHOP FLOOR PRODUCTION PLAN].[cycletime] FROM [SHOP FLOOR PRODUCTION PLAN] WHERE [SHOP FLOOR PRODUCTION PLAN].[MACHINE]='$this->name' 在[车间生产计划]中选择[车间生产计划]。[机器],[车间生产计划]。[周期]。[车间生产计划]。[机器] ='$ this-> name'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.