显示表中mysql数据库的数据

时间:2015-01-19 21:33:49

标签: php mysql

我想从我的数据库中获取数据并使用php在表中进行回显,但是当我将代码上传到服务器并执行它时,我只是得到一个空白区域。我做错了什么?

<?php 
$servername = "***";
$username = "***";
$password = "***";
$dbname = "economics";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$query = "SELECT * FROM Points";

$result = mysql_query($query);

echo "<table>";

while($row = mysql_fetch_array($result)){

echo "<tr><td>" . $row['Alexis'] . "</td><td>" . $row['Anthony'] . "</td></tr>";
}

echo "</table>";

mysql_close();

?>

1 个答案:

答案 0 :(得分:0)

首先,您正在创建一个sqli连接,但正在尝试使用sql来获取数组:while($row = mysql_fetch_array($result))可能会尝试将其更改为while($row = mysqli_fetch_array($result))$result = mysql_query($query);更改为{{1} }。这可能有所帮助。也将结尾更改为$result = mysqli_query($query);