我想将我的sql数据库中的所有行输出到表中,但我只能输出1行。 到目前为止,这是我的代码:
<?php
$users = mysqli_query($database, "SELECT * FROM people");
if (mysqli_num_rows($users) == 0) {
echo ('No matches in the database');
}
while ($row = mysqli_fetch_array($users)){
$name = $row['name'];
$postcode = $row['postcode'];
$email = $row ['email'];
}
?>
<table>
<tr><td>Name:</td></tr>
<tr><td><?php echo ($name) ?></td></tr>
<tr><td>postcode:</td></tr>
<tr><td><?php echo ($postcode) ?></td></tr>
<tr><td>email:</td></tr>
<tr><td><?php echo ($email) ?></td></tr>
</table>
这只输出一个,如何输出所有行?
答案 0 :(得分:1)
你需要将表放在一个循环中,如下所示:
def indices_of_list_element_duplicates(x):
seen = set()
for index, element in enumerate(x):
if isinstance(element, list):
element = tuple(element)
if element not in seen:
seen.add(element)
else:
yield index
def list_element_duplicates(x):
indices = list(indices_of_list_element_duplicates(x))
return [x[index] for index in indices]
a = [[1, 2], [1, 2], [2, 2], [3, 2], [4, 2], [5, 2], [5, 2]]
print(list_element_duplicates(a))
print("--------------------------------------------------------------------------------")
b = [[10], [15], [20], [10, 10], [10, 15], [10, 20], [15, 10], [15, 15], [15, 20], [20, 10], [20, 15], [20, 20], [10, 10, 10], [10, 10, 15], [10, 10, 20], [10, 15, 10], [10, 15, 15], [10, 15, 20], [10, 20, 10], [10, 20, 15], [10, 20, 20], [15, 10, 10], [15, 10, 15], [15, 10, 20], [15, 15, 10], [15, 15, 15], [15, 15, 20], [15, 20, 10], [15, 20, 15], [15, 20, 20], [20, 10, 10], [20, 10, 15], [20, 10, 20], [20, 15, 10], [20, 15, 15], [20, 15, 20], [20, 20, 10], [20, 20, 15], [20, 20, 20], [10], [15], [20], [10, 10], [10, 15], [10, 20], [15, 10], [15, 15], [15, 20], [20, 10], [20, 15], [20, 20], [10, 10, 10], [10, 10, 15], [10, 10, 20], [10, 15, 10], [10, 15, 15], [10, 15, 20], [10, 20, 10], [10, 20, 15], [10, 20, 20], [15, 10, 10], [15, 10, 15], [15, 10, 20], [15, 15, 10], [15, 15, 15], [15, 15, 20], [15, 20, 10], [15, 20, 15], [15, 20, 20], [20, 10, 10], [20, 10, 15], [20, 10, 20], [20, 15, 10], [20, 15, 15], [20, 15, 20], [20, 20, 10], [20, 20, 15], [20, 20, 20], [10], [15], [20], [10, 10], [10, 15], [10, 20], [15, 10], [15, 15], [15, 20], [20, 10], [20, 15], [20, 20], [10, 10, 10], [10, 10, 15], [10, 10, 20], [10, 15, 10], [10, 15, 15], [10, 15, 20], [10, 20, 10], [10, 20, 15], [10, 20, 20], [15, 10, 10], [15, 10, 15], [15, 10, 20], [15, 15, 10], [15, 15, 15], [15, 15, 20], [15, 20, 10], [15, 20, 15], [15, 20, 20], [20, 10, 10], [20, 10, 15], [20, 10, 20], [20, 15, 10], [20, 15, 15], [20, 15, 20], [20, 20, 10], [20, 20, 15], [20, 20, 20], [10], [15], [20], [10, 10], [10, 15], [10, 20], [15, 10], [15, 15], [15, 20], [20, 10], [20, 15], [20, 20], [10, 10, 10], [10, 10, 15], [10, 10, 20], [10, 15, 10], [10, 15, 15], [10, 15, 20], [10, 20, 10], [10, 20, 15], [10, 20, 20], [15, 10, 10], [15, 10, 15], [15, 10, 20], [15, 15, 10], [15, 15, 15], [15, 15, 20], [15, 20, 10], [15, 20, 15], [15, 20, 20], [20, 10, 10], [20, 10, 15], [20, 10, 20], [20, 15, 10], [20, 15, 15], [20, 15, 20], [20, 20, 10], [20, 20, 15], [20, 20, 20]]
print(list_element_duplicates(b))
从此处删除'}'
<?php
$users = mysqli_query($database, "SELECT * FROM people");
if (mysqli_num_rows($users) == 0) {
echo ('No matches in the database');
}
while ($row = mysqli_fetch_array($users)){
$name = $row['name'];
$postcode = $row['postcode'];
$email = $row ['email'];
然后在表格后面添加它以创建循环