请检查此mysql查询中的错误我收到以下错误

时间:2016-07-04 16:40:43

标签: php mysql mysqli adrotator

我收到以下错误:
警告:mysqli_fetch_assoc()期望参数1为mysqli_result,给定布尔值 我试图改变代码,但没有任何使用可以帮助我,请使这个代码可行。 我的代码是:

<?php
/*home page bannerrotator*/
$sql="SELECT homelb,bdetails1,bdetails2,abovefoo1,abovefoo2 FROM 
adsettings WHERE NOT(hview1=hometotal AND hview2=bdtotal1 AND  
hview3=bdtotal2 AND hview4=foototal1 AND hview5=foototal2) LIMIT 10";
$result=mysqli_query($connection,$sql);
$rows=mysqli_num_rows($result);
if($rows!=0)
{
$leaderboard = array();
$bd1=array();
$bd2=array();
$foo1=array();
$foo2=array();
$i=0;
while ($row = mysqli_fetch_assoc($result)) { 
$leaderboard[i]=$row['homelb'];
$bd1[i]=$row['bdetails1'];
$bd2[i]=$row['bdetails2'];
$foo1[i]=$row['abovefoo1'];
$foo2[i]=$row['abovefoo2'];
i++;
}
shuffle($leaderboard);
shuffle($bd2);
shuffle($bd1);
shuffle($foo1);
shuffle($foo2);
}
else
{
$leaderboard[0]="Advertise Here";
$bd1[0]="Advertise Here";
$bd2[0]="Advertise Here";
$foo1[0]="Advertise Here";
$foo2[0]="Advertise Here";
}
/*login page adverts*/

?>

1 个答案:

答案 0 :(得分:0)

这个答案不会解决您的问题,但可以帮助您自己解决问题。

您的查询中可能存在错误。要找出可能执行以下操作的错误:

$result = mysqli_query($connection, $sql);
if (!$result) {
    printf("Errormessage: %s\n", mysqli_error($connection));
}

这将输出mysql错误,以便您解决问题。

修改

您可能只想这样做:

SELECT
homelb,
bdetails1,
bdetails2,
abovefoo1,
abovefoo2
FROM adsettings
WHERE hview1!= hometotal
AND hview2!= bdtotal1
AND hview3 != bdtotal2
AND hview4 != foototal1
AND hview5 != foototal2
LIMIT 10