mysql boolean给出但结果显示

时间:2017-03-15 22:00:56

标签: php mysql

当我从mysql显示数据时,我收到此警告:

警告:mysql_fetch_assoc()期望参数1为资源,布线在第821行的/home/zh004600/www_root/public/text/atomia/find.php中给出

但我看到了结果。如果没有这个警告我该怎么办?第821行与while循环“while($ row1 = mysql_fetch_assoc($ result1)){”

有人可以帮忙吗?

    echo '<table class="files" cellspacing="3" cellpadding="3">';

                                    $query = 

'SELECT * FROM files WHERE cz ='.$Podp;
                                $result = mysql_query($query);
                                $resultCount = mysql_num_rows($result) + 3;

                                for ($k=0;$k<$resultCount;$k+=4) {
                                    $j= $k-4;
                                        echo '<tr class="files">';
                                            if ($j == 0) {
                                                $query1 = 'SELECT * FROM files WHERE cz ='.$Podp.' LIMIT 4'; 
                                            } else {
                                                $query1 = 'SELECT * FROM files WHERE cz ='.$Podp.' LIMIT 4 OFFSET '.$j;
                                            }
                                                $result1 = mysql_query($query1);
                                                    while ($row1 = mysql_fetch_assoc($result1)) {
                                                        $nazov = $row1['nazov'];
                                                        $cesta = $row1['cesta'];                            
                                                        echo '<th class="files"><a href="'.$cesta.'" download><img src="img/icons/pdf.png" width="45"></a><br>'.$nazov.'</th>';

                                                    }
                                        echo '</tr>';
                                }
                        echo '</table>';

1 个答案:

答案 0 :(得分:2)

只需添加此支票

即可
if($result1){
像这样:

$result1 = mysql_query($query1);
    if($result1){ // <-- THIS CHECK
        while ($row1 = mysql_fetch_assoc($result1)) {
            $nazov = $row1['nazov'];
            $cesta = $row1['cesta'];                            
            echo '<th class="files"><a href="'.$cesta.'" download><img src="img/icons/pdf.png" width="45"></a><br>'.$nazov.'</th>';

        }
    }