比较多维数组中的两个 DATETIME 字段并返回值或索引



我有一个用户表。我正在查看的每行有 2 个DATETIME。我将查看$lastLog日期和$lastReceived(对于上次收到的潜在客户),并确定哪个较新,成为他们的$eligibleTime.然后,我们将寻找最旧的$eligibleTime来选择哪个用户应该获得潜在客户。我正在筛选用户,以确保他们以潜在客户所处的适当状态获得许可,并且他们尚未达到每日配额。

我在想也许我构建了错误的多 d 数组,应该将所有$lastLog日期和$lastReceived日期分组到它们自己的数组中并运行max($array)或类似的东西。

我该怎么看这个?我使用以下命令构建了一个多维数组:

    $sql = "SELECT `lastLog`,`firstName`,`lastReceived` FROM customers";
    $sql = mysqli_query($conn,$sql);
    $result = array();
    while($line = mysqli_fetch_assoc($sql)){
      $result[] = $line;
    }

它返回以下数据:

> Array ( [0] => Array ( [lastLog] => 2015-06-12 02:00:00 [firstName] => Nathaniel [lastReceived] => 2015-06-12 05:16:10 ) [1] => Array ( [lastLog] => 2015-06-12 01:00:00 [firstName] => Ignacio [lastReceived] => 2015-06-01 10:00:00 ) [2] => Array ( [lastLog] => 2015-06-12 00:00:00 [firstName] => James [lastReceived] => 2015-06-08 00:00:00 ) [3] => Array ( [lastLog] => 2015-06-12 04:00:00 [firstName] => Robert [lastReceived] => 2015-06-10 00:00:00 ) ) 

谢谢你,内特

多亏了

Marc B,这个问题得到了解决。

$sql = mysqli_query($conn,
   "SELECT firstName, greatest(lastLog, lastReceived) AS eligibleTime 
    FROM customers 
    ORDER BY eligibleTime DESC
    LIMIT 1");
$result = mysqli_fetch_assoc($sql);
print_r($result);

相关内容

  • 没有找到相关文章

最新更新