我编写了一个查询来获取表中的数据,但得到了上述错误: -
<html>
<body>
<table align="center" width="100%">
<tr>
<td>
<?php
$con=mysqli_connect("localhost","root","") or die("Failed to connect with database!!!!");
mysqli_select_db($con,"data");
$result = mysqli_query($con,"Select @cust_rank :=NULL,@current_cust :=NULL;
SELECT customer_name,item_value,cust_rank,site,item_code FROM (SELECT b.site,b.customer_name,b.item_value, @cust_rank := IF(@current_cust=b.customer_name, @cust_rank+1,1) AS cust_rank, @current_cust:=b.customer_name,b.item_code from (SELECT site, item_code, customer_name, SUM(item_amount) AS item_value FROM cdata WHERE Invoice_type='Excise' AND Item_code LIKE 'FG%' AND concat(customer_name,'|',site) in (select distinct (concat(a.customer_name,'|',a.site)) from (SELECT site, customer_name, SUM(item_amount) Total_value FROM cdata WHERE site='BDD2' GROUP BY site, customer_name ORDER BY Total_value DESC limit 10) a) GROUP BY site, customer_name,item_code ORDER BY customer_name, item_value DESC )b ) c where cust_rank<=5
");
echo "<table border='1' cellpadding='5' cellspacing='2' style='border:black; ' align='center'>
<tr>
<th id='td'>Customer Name</th>
<th id='td'>Item Value</th>
<th id='td'>Cust Rank </th>
<th id='td'>Site</th>
<th id='td'>Item Code</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td align='center'>" . $row['customer_name'] . "</a></td>";
echo "<td align='center'>" . $row['item_value'] . "</td>";
echo "<td align='center'>" . $row['cust_rank'] . "</td>";
echo "<td align='center'>" . $row['site'] . "</td>";
echo "<td align='center'>" . $row['item_code'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
</td>
</tr>
</table>
</body>
</html>
答案 0 :(得分:1)
布尔值false表示没有返回结果,但函数需要mysql结果。
答案 1 :(得分:0)
使用
$count = count($result);
if(!empty($count))
{
//$result contain data
while($row = mysqli_fetch_array($result,MYSQLI_ASSOC))
{
}
}
else
{
//$result is empty
}