我正在尝试显示一个包含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>
答案 0 :(得分:0)
您的查询在选择列Date of birth
时出错,因为它有空格,请尝试:
"SELECT ID, Name, Role, Responsibilities, Age, `Date of birth`, Email FROM person"