PHP MySQL - 其中相关子句不读取变量

时间:2016-08-11 09:02:55

标签: php mysql variables where correlation

我已经拥有的以下代码完全符合我的要求,除了一件事......

date(d.added) = '$date'我还需要登录等于$date

我已尝试将其添加到外部和WHERE语句中,但似乎无法将其正确地添加

SELECT d.*
FROM data d
WHERE date(d.added) = '$date' AND 
      d.logon = (SELECT MIN(d2.logon) FROM data d2 WHERE d2.name = d.name);

如果您需要更多信息,请告诉我

编辑

这是它目前的外观,但我不希望它显示结果,除非添加和登录都是相同的日期 enter image description here

$sql = "SELECT d.* FROM data d WHERE date(d.added) = '$date' AND d.logon = (SELECT MIN(d2.logon) FROM data d2 WHERE d2.name = d.name);";

$result = $conn->query($sql);

3 个答案:

答案 0 :(得分:0)

您尝试更改:

 '$date'

 "$date"

答案 1 :(得分:0)

请您尝试以下格式。

-webkit-appearance

您将使用以下格式

执行查询

$query="SELECT d.* FROM data d WHERE date(d.added) = '".$date."' AND d.logon = (SELECT MIN(d2.logon) FROM data d2 WHERE d2.name = d.name)";

答案 2 :(得分:0)

管理它:

SELECT d.* FROM data d WHERE date(d.added) = '$date' AND d.logon = (SELECT MIN(d2.logon) FROM data d2 WHERE d2.name = d.name AND date(d2.logon) = '$date');