我有像这样的SQL查询
DECLARE @Date datetime = GETDATE()
DECLARE @VJ datetime = DATEADD(DAY, DATEPART(WEEKDAY, @Date), DATEADD(ww, DATEDIFF(ww,0,DATEADD(YEAR,-1, @Date)), 0)-1)
SELECT 'Printed:', [7],[8],[9],[10],[11],[12],[13],[14],[15],[16],[17],[18],[19],[20]
FROM (SELECT DATEPART(HOUR, prWhen) prHour,
COUNT(VID) CountPr
FROM myDBO
WHERE CONVERT(varchar(10), prWhen, 104)=CONVERT(varchar(10), @Date,104)
GROUP BY DATEPART(HOUR,prWhen)) as SRC
PIVOT (AVG(CountPz)
FOR prHour IN ([7],[8],[9],[10],[11],[12],[13],[14],[15],[16],[17],[18],[19],[20])) as pvt
我每小时检查打印多少张纸。查询正在运行。但现在我想用这些数据制作图表(chart.js)。首先我创建了一个php文件:
<?php
$serverName = "....";
$connectionInfo = array( "Database"=>"...", "Uid" => "...", "PWD" =>
"....");
$conn = sqlsrv_connect($serverName, $connectionInfo);
$sql="...."; //copied the query from above
$result = sqlsrv_query($conn, $sql);
$row = sqlsrv_fetch_array($result);
echo $row['pvt'];
?>
这是我的问题,如何获得pvt行。
命令echo $row['pvt'];
无效。我收到了通知
注意:未定义的索引:pvt
如何将其提取到数组中? key:value =&gt; 7:71