为什么不输出我的MySQL Artist表中的所有数据?

时间:2016-03-31 16:02:11

标签: php mysql

我写了一个非常简单的查询来输出Artist表中的所有数据,并将它们输出到已建立的表中。我已经仔细检查了数据库并且所有拼写都是正确的,但是由于某种原因我没有得到任何数据输出。

连接器代码

<?php

$conn = mysqli_connect("localhost", "b4014107", "Windows1", "b4014107_db2") or die (mysqli_connect_error());

?>

主要代码

!DOCTYPE HTML>
<html>
<head>
<title>View Artist Table</title>
</head>
<body>

<?php
//Includes speicifed details in order to connect to MySQL
include('ConnectorCode.php');

//mysql_query command is used to select data from Artist table
$result = mysqli_query("SELECT * FROM tbl_Artist");

echo "<table border='1'>";
echo "<tr> <th>Artist ID</th> <th>Artist Name</th> </tr>";

//Results are looped and then displayed in tables
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row ['Artist_id'] . "</td>";
echo "<td>" . $row ['Artist_Name'] . "</td>";
echo "</tr>";
}

echo "</table>";

//Connection is closed
      mysqli_close($conn);


 ?>

<p><a href="ArtistNew.php">Add a new Artist</a></p>
<p><a href="ArtistEdit.php">Edit a current Artist</a></p>
</body>
</html>

我做错了什么?

2 个答案:

答案 0 :(得分:0)

我认为这是你的问题:

使用:$result->fetch_assoc()

而不是:mysqli_fetch_array($result)

答案 1 :(得分:0)

我找到了解决方案!我只需要在mysqli_query中添加$ conn。

$result = mysqli_query($conn, "SELECT * FROM tbl_Artist");