比较多维数组中的两个 DATETIME 字段和 return 一个值或索引
Compare two DATETIME fields from multidimensional array and return a value or index
我有一个用户table。我正在查看每行 2 DATETIME
。我将查看 $lastLog
日期和 $lastReceived
(最后收到的线索)并确定哪个更新并成为他们的 $eligibleTime
。然后我们将寻找最老的 $eligibleTime
到 select 哪个用户应该获得潜在客户。我正在筛选用户,以确保他们在潜在客户所处的适当状态下获得许可,并且还确保他们没有达到每日配额。
我在想,也许我错误地构建了多维数组,应该将所有 $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);
我有一个用户table。我正在查看每行 2 DATETIME
。我将查看 $lastLog
日期和 $lastReceived
(最后收到的线索)并确定哪个更新并成为他们的 $eligibleTime
。然后我们将寻找最老的 $eligibleTime
到 select 哪个用户应该获得潜在客户。我正在筛选用户,以确保他们在潜在客户所处的适当状态下获得许可,并且还确保他们没有达到每日配额。
我在想,也许我错误地构建了多维数组,应该将所有 $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);