这是代码,为什么我会收到此错误?
警告:mysqli_num_rows()期望参数1为mysqli_result,boolean given
on $ conta_artisti = mysqli_num_rows($ preferenze1);
如果查询没有找到项目?
session_start();
$mail = $_SESSION['Mail'];
$query = $mysqli->query("SELECT * FROM valutazione WHERE email='$mail'");
$countresults = mysqli_num_rows($query);
if($countresults == 0)
{
$preferenze = $mysqli->query("DROP VIEW IF EXISTS artisti_p"); //recupero id degli artisti preferiti
$preferenze1 = $mysqli->query("CREATE VIEW artisti_p AS SELECT idartista FROM artisti_preferiti WHERE email='$mail'");
if($preferenze1)
{
$conta_artisti = mysqli_num_rows($preferenze1);
if($conta_artisti > 0)
{
$preferenze = $mysqli->query("DROP VIEW IF EXISTS album_p");
$album_artita_p = $mysqli->query("CREATE VIEW album_p AS SELECT idalbum FROM artisti_p JOIN artisti_album ON artisti_p.idartista=artisti_album.idartista");
$preferenze = $mysqli->query("DROP VIEW IF EXISTS info_album_p");
$info_album_artista_p = $mysqli->query("CREATE VIEW info_album_p AS SELECT * FROM album_p JOIN album ON album_p.idalbum=album.ID'");
$index_p = 0;
while($row = mysqli_fetch_array($info_album_artista_p))
{
$id_p[$index_p]=$row['idalbum'];
$nome_p[$index_p]=$row['NOME'];
$casa_p[$index_p]=$row['CASA_DISCOGRAFICA'];
$anno_p[$index_p]=$row['ANNO_USCITA'];
$durata_p[$index_p]=$row['DURATA_ALBUM'];
$index_p++;
}
}
}
答案 0 :(得分:0)
失败时返回FALSE。
您的代码假定不会发生这种情况。它刚刚做到了。处理那个案子:
$query = $mysqli->query("SELECT * FROM valutazione WHERE email='$mail'");
if (! $query) {
die("error");
}
$countresults = mysqli_num_rows($query);