This question already has answers here:
mysql_fetch_array()/mysql_fetch_assoc()/mysql_fetch_row()/mysql_num_rows etc… expects parameter 1 to be resource or result
                                
                                    (32个答案)
                                
                        
                                5年前关闭。
            
                    
我试图在我的family_spouse表中显示所有原始文件



      <?php



    $query = "SELECT FROM family_spouse";
    $result = mysql_query ($query);

    echo "<table border='1'>
    <tr>
    <th>Family Type</th>
    <th>Name</th>
    <th>Gender</th>
    </tr>";

    while($row = mysql_fetch_array($result))
    {
    echo "<tr>";
    echo "<td>" . $row['spouse_type'] . "</td>";
    echo "<td>" . $row['spouse_name'] . "</td>";
    echo "<td>" . $row['spouse_gender'] . "</td>";
    echo "</tr>";
    }
    echo "</table>";

    ?>


当我运行代码时,此错误出现Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\eprofile\dashboard.php on line 598

598行

while($row = mysql_fetch_array($result))

最佳答案

该错误在您的查询中,可能应该是:

$query = "SELECT * FROM family_spouse";


如果您不愿意检查查询的返回值,就会知道这一点。

假设您已正确连接到数据库,则应执行以下操作:

$query = "SELECT * FROM family_spouse";
$result = mysql_query($query) or die(mysql_error());


请注意,不建议使用mysql_*(),并且您应该使用mysqli_*PDO

09-19 16:18