我有mysql表性能(id,名称,类型,值,日期),我正在使用动态查询,如
SELECT performance.name,
performance.type,
Coalesce(Sum((CASE
WHEN (performance.date = '2017-11-02') THEN performance.value
END)), 0) AS "2-Nov"
FROM performance
WHERE performance.type = 'Max'
GROUP BY performance.name,
performance.type
根据开始日期和结束日期获取datewise列输出。
我使用mysql_fetch_array函数echo "<td>" . $row['2-Nov(In)'] . "</td>";
在php页面上打印mysql查询结果,并且使用静态条目可以很好地解决问题。
我想基于动态mysql查询在我的PHP代码上添加自动增量列,以便$ row []的数量将根据开始日期和结束日期在数组内部更改。
例如:
`echo "<td>" . $row['2-Nov(In)'] . "</td>";
`echo "<td>" . $row['3-Nov(In)'] . "</td>";`
`echo "<td>" . $row['4-Nov(In)'] . "</td>";` etc.
我的查询示例输出
name | type | 2-Nov |
+-----------------------------------------+
| Name1 | Max | 72.97 |
| Name2 | Max | 34.2 |
| Name3 | Max | 15.14 |
| Name4 | Max | 11.38 |
+-----------------------------------------+-
我使用以下代码打印查询输出
$sql = "$a $b $d $d";
$result = @mysql_query($sql,$connection) or die(mysql_error());
while ($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row[name] . "</td>";
echo "<td>" . $row[type] . "</td>";
echo "<td>" . $row['2-Nov(In)'] . "</td>"; <-- start date
echo "<td>" . $row['3-Nov(In)'] . "</td>"; $row auto increase/decrease
echo "<td>" . $row['4-Nov(In)'] . "</td>"; based on start and end date
echo "<td>" . $row['5-Nov(In)'] . "</td>"; <-- end date
echo "</tr>";
}