我正在使用以下代码获取 2列中的计数-重新尝试日期和保留日期
{{1}}
我得到如下结果,在这前6个值来自 reattemptdate 列,接下来的6个值来自 holddate 列,如何显示文本Hold而不是在最后6个重新尝试图片下方的行:
答案 0 :(得分:2)
您可以根据“ Held”列使用逻辑: 例如:
...
foreach ($results as $result)
{
if ($result['Held']==0){
$header = "Reattemptdate";
} else {
$header = "holddate";
}
echo $header.": ".$result['count']."<br>";
}
或在结果集中添加一个显式标头,如下所示:
<?php
$sql = "SELECT employeename, DATE(reattemptdate) as date,
COUNT(*) as count, 0 as Held, 'reattemptdate' as header FROM orders
WHERE DATE(reattemptdate) = CURDATE()
GROUP BY employeename, date
UNION
SELECT employeename, DATE(holddate) as date,
COUNT(*) as count, 1 as Held, 'holddate' as header FROM orders
WHERE DATE(holddate) = CURDATE()
GROUP BY employeename, date
";
$results = $db_handle->runSelectQuery($sql);
$numrowsresult =$results[0]['count'];
foreach ($results as $result)
{
echo $result['header'].": ".$result['count']."<br>";
}