Select 来自我的表,其中日期 = 特定日期

Select from my tabel where date = specific date

我在 table 的约会对象是 TIMESTAMP 这样的 2016-05-28 18:39:00

现在我正在尝试 select 从 table where date = 2016-05-28

这是我的查询

    $getReport = $db->prepare('SELECT a.proId, a.userId, DATE(a.date), a.status, a.canceledBy, b.id, b.pName, b.pPrice FROM purchaseshistory AS a INNER JOIN products AS b ON(a.proId=b.id) WHERE a.date=?');

    $getReport->bind_param('i', $dateOfBirth);
    $getReport->execute();
    $getReport->bind_result($proId, $userId, $date, $status, $canceledBy, $id, $pName, $pPrice);
$getReport->store_result();
while ($getReport->fetch()) {

日期来自这里

$dateOfBirth = $_POST['dateOfBirth'];

结果为空

您已将 a.date 转换为 SELECT 中的 DATE,但未在 WHERE 子句中转换,我建议按如下方式修改您的查询:

SELECT 
  ph.proId, ph.userId, DATE(ph.date), ph.status, ph.canceledBy,
  p.id, p.pName, p.pPrice 
FROM purchaseshistory AS ph 
  INNER JOIN products AS p ON ph.proId = p.id
WHERE DATE(ph.date) = ?

您可能需要正确的日期格式

SELECT a.proId, a.userId, 
DATE(a.date), a.status, a.canceledBy, b.id, b.pName, b.pPrice 
FROM purchaseshistory AS a 
INNER JOIN products AS b ON(a.proId=b.id) 
WHERE date_format(a.date,'%Y-%m-%d') = ?