从mysql db获取时出现PHP错误

时间:2017-06-20 19:26:01

标签: php html mysqli html-table

我知道这个问题已经解决但是这个解决方案对我不起作用。

这是PHP中的代码;我检查了它的连接性所有基本查询都在工作但不是这种类型。

以下是代码:

    con=mysqli_connect("localhost","root","root","irctc_book");

if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$query = "SELECT time_format(SETTLEMENT_DATE,\'%H:%i\') AS \"TIME\",\n"
. "SUM(CASE WHEN CORPORATE_ID=1328727040 THEN 1 ELSE 0 END ) AS \"TOTAL\",\n"
. "SUM(CASE WHEN CORPORATE_ID=1328727040 AND ( QUOTA_CODE=\'0\' OR   QUOTA_CODE =\'1\') THEN 1 ELSE 0 END) AS \"Non-Tatkal\",\n"
. "SUM(CASE WHEN CORPORATE_ID=1328727040 AND QUOTA_CODE=\'2\' THEN 1 ELSE 0 END) AS \"Tatkal\"\n"
. "FROM ticket\n"
. "WHERE CURRENT_RES_STATUS NOT IN (9,10,11,16)\n"
. "AND PNR_NUMBER > 0\n"
. "AND HOUR(SETTLEMENT_DATE)=08\n"
. "GROUP BY time_format(SETTLEMENT_DATE,\'%H:%i\')\n"
. "ORDER BY SETTLEMENT_DATE";
$result = mysqli_query($con,$query);
echo "<table   border='1'><tr><th>Time</th><th>TRAIN_NO</th><th>PNR_NUMBER</th><th>TRAIN_NAME</th></tr>";
while($row = mysqli_fetch_assoc($result))
{
echo "<tr>";
echo "<td>" . $row['TIME'] . "</td>";
echo "<td>" . $row['TOTAL'] . "</td>";
echo "<td>" . $row['Non-Tatkal'] . "</td>";
echo "<td>" . $row['tatkal'] . "</td>";
echo "</tr>";
}
echo "</table>";

mysqli_close($con);

我得到的错误是

  

警告:mysqli_fetch_assoc()期望参数1为mysqli_result,给定布尔值

请感谢任何帮助。

0 个答案:

没有答案