无论何时我在phpmyadmin中尝试以下查询,都可以正常工作:
SELECT CAST(DATETIME AS DATE), Provider, COUNT(Provider)
FROM purchases
GROUP BY CAST(DATETIME AS DATE), Provider
ORDER BY CAST(DATETIME AS DATE) DESC
尽管如此,当我将其放入PHP脚本时,我总是收到一个布尔值:
$sql="SELECT CAST(DATETIME AS DATE), Provider, COUNT(Provider)
FROM purchases
GROUP BY CAST(DATETIME AS DATE), Provider
ORDER BY CAST(DATETIME AS DATE) DESC";
if (mysqli_query($con,$sql))
{
$result = mysql_query($sql);
while($row = mysql_fetch_assoc($result)) {
echo $row['CAST(DATETIME AS DATE)'];
echo $row['Provider'];
echo $row['COUNT(Provider)'];
}
}
else
{
echo "Error creating table: " . mysqli_error($con);
}
mysqli_close($con)
;
我非常感谢有关如何解决此问题的一些建议。
答案 0 :(得分:0)
此代码如下所示,因此可以正常工作
您在所有查询中都使用mysqli
,并检查$result
是否比打印记录有价值,否则打印了error
消息
$result = mysqli_query($con,$sql);
if($result)
{
while($row = mysqli_fetch_assoc($result)){
echo $row['CAST(DATETIME AS DATE)'];
echo $row['Provider'];
echo $row['COUNT(Provider)'];
}
}
else
{
echo "Error creating table: " . mysqli_error($con);
}
mysqli_close($con)