这个问题在这里已经有答案了:
在mysql中何时使用单引号、双引号和反引号(13个答案)
mysqli_fetch_assoc()需要参数/调用成员函数bind_param()时出错。如何获得实际的mysql错误并修复它(1个答案)
两年前关门了。
我试图显示一个有6个值的数组,但我真的不知道怎么做。我试着用 num_rows
但似乎不行。我不知道怎么修。
<?php<br>
//four variables to connect to the database<br>
$host= "localhost";<br>
$username="root";<br>
$password='';<br>
$database="pd00255_coursework2_com1025";<br>
//create a database connection instance
$mysqli = new mysqli($host, $username, $password, $database);<br>
//if there are any values in the table, display them one at a time.
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;<br>
}<br>
echo $mysqli->host_info . "<br>";<br>
$sql = "SELECT ID, Name ,Role, Responsibilities, Age, Date of birth, Email FROM person";<br>
$result = $mysqli->query($sql);<br>
if ($result->num_rows > 0) {<br>
// output data of each row<br>
while($row = $result->fetch_assoc()) {<br>
echo "id: " . $row["ID"]. " - ID: " . $row["Name"]. " " . $row["Role"]. " " . $row["Responsibilities"]. "Responsibilities" . $row["Age"]. "Age" . $row["Date of birth"]. "Date of birth" . $row["Email"]."Email" "<br>";
}<br>
} else {<br>
echo "0 results";<br>
}<br>
$mysqli->close;<br>
?><br>
1条答案
按热度按时间7xzttuei1#
您的查询在选择列时出错
Date of birth
,因为它有空格,请尝试: