【发布时间】:2016-12-09 18:57:11
【问题描述】:
我正在尝试在来自 MySQL 数据库的网页上显示一个表格,但它现在可以工作了!这是我的代码:
<?php
function list_schools() {
$conn = mysqli_connect("localhost", "root", "", "Database_Project");
if ($conn === false) {
die("Could not connect:" . mysqli_connect_error());
}
$output = "";
$result = mysqli_query($conn, "SELECT school_id, name, address, phone_number, email, type FROM Schools;") or die('cannot show tables');
while ($row = mysqli_fetch_array($result)){
$output .= '
<tr>
<td>' . $row['school_id'] . '</td>
<td>' . $row['name'] . '</td>
<td>' . $row['address'] . '</td>
<td>' . $row['phone_number'] . '</td>
<td>' . $row['email'] . '</td>
<td>' . $row['type'] . '</td>
</tr>';
}
return $output;
}
$exec_func = list_schools();
?>
<table cellpadding="0" cellspacing="0" width="100%" class="sortable">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Address</th>
<th>Phone Number</th>
<th>Email</th>
<th>Type</th>
<td> </td>
</tr>
</thead>
<tbody>
<?php echo exec_func; ?>
</tbody>
</table>
每当我尝试在浏览器上显示它时,我都会得到以下信息:
1
无法显示来自 1 的列
我做错了什么?
【问题讨论】:
-
您选择的是
school_id,而不是ID -
我更正了,但仍然没有表格显示@aynber
-
另外,
exec_func是什么?如果您尝试回显返回变量,则会丢失美元符号。 -
@aynber 不,恐怕不是这样;还是不行
-
您是否仍然收到“无法显示来自 1 的列”或其他消息?现在屏幕上显示的是什么?