error mysql_fetch_array()期望参数1是资源

时间:2017-01-06 11:19:48

标签: php html

你们可以帮助我解决这个错误吗?

  

“警告:mysql_fetch_array()期望参数1是资源,   第31行“blablabla”中给出的对象。“

我已经尝试了很多我找到的解决方案,但它仍然导致我犯了这个错误。

<html>
    <head>
        <title>
            Autores
        </title>
    </head>
    <body>
        <?php        
$link = mysqli_connect("", "", "", "");
if($link === false){
    die("ERRRO: Não foi possivel a conexão com a base de dados. " . mysqli_connect_error());
}        
$sql = 'SELECT * FROM autores';
$result = mysqli_query($link, $sql) or die($sql."<br/><br/>".mysql_error());        
echo "<p><b>Ver todos</b> | <a href='view-paginated.php?page=1'>Ver por página</a></p>";       
echo "<table border='1' cellpadding='10'>";        
echo "<tr> <th>ID</th> <th>Autor</th><th></th> <th></th></tr>";        
while($row = mysqli_fetch_array($result )) {  
    // echo out the contents of each row into a table
    echo "<tr>";   
    echo '<td>' . $row['a_id'] . '</td>'; 
    echo '<td>' . $row['a_nome'] . '</td>';
    echo '<td><a href="edit.php?id=' . $row['id'] . '">Edit</a></td>';
    echo '<td><a href="delete.php?id=' . $row['id'] . '">Delete</a></td>';
    echo "</tr>";
}
// close table>
echo "</table>";
        ?>
        <p>
            <a href="new.php">Add a new record</a>
        </p>
    </body>
</html>

谢谢,

GonçaloPinho

2 个答案:

答案 0 :(得分:1)

while($row = mysqli_fetch_array($result )) {  //you have to change mysql to mysqli
    // echo out the contents of each row into a table
    echo "<tr>";   
    echo '<td>' . $row['a_id'] . '</td>'; 
    echo '<td>' . $row['a_nome'] . '</td>';
    echo '<td><a href="edit.php?id=' . $row['id'] . '">Edit</a></td>';
    echo '<td><a href="delete.php?id=' . $row['id'] . '">Delete</a></td>';
    echo "</tr>";
}

答案 1 :(得分:0)

为什么你不能这样做

$link = mysqli_connect("HOST", "UNAME", "PASS", "Database");

$query = "SELECT * FROM autores";
$result = $link->query($query);

while($row = $result->fetch_array())
{
// Your stuff
}