【发布时间】:2018-01-08 13:51:56
【问题描述】:
我正在尝试显示一个包含 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>
【问题讨论】:
-
输出的是什么?