[英]PHP, HTML and MySqli - how to show all data from specific column in one table row
I have a database table called names
. 我有一个名为
names
的数据库表。 I have 2 columns there - "id" and "name". 我在那里有2列-“ id”和“ name”。 In the column "name" I have some data like:
在“名称”列中,我有一些数据,例如:
Inna
因那
Petia
Vaska
瓦斯卡
Kote
Kote
Pepa
佩帕
I want this data to be shown in a html table like this: 我希望将此数据显示在html表中,如下所示:
<table> <tr> <td>Inna</td> <td>Petia</td> <td>Vaska</td> <td>Kote</td> <td>Pepa</td> <tr> </table>
My PHP code is: 我的PHP代码是:
<?php
$q= mysqli_query($db, 'SELECT * FROM names');
echo '<table>';
while ($row = mysqli_fetch_assoc($q)){
echo '<tr>';
foreach($row as $value) {
echo "<td>$value</td> ";
}
echo ' </tr>';
}
but this did not work for me! 但这对我没有用!
try this: 尝试这个:
echo '<table>';
while ($row = mysqli_fetch_assoc($q)){
echo '<tr>';
//foreach($row as $value) {
echo "<td>" . $row['name'] . "</td>";
// }
echo '</tr>';
}
<?php
$q= mysqli_query($db, 'SELECT * FROM names');
echo '<table>';
echo '<tr>';
while ($row = mysqli_fetch_assoc($q)){
foreach($row as $value) {
echo "<td>$value</td> ";
}
}
echo ' </tr>';
This is the solution of my problem: I just has to put 这是我的问题的解决方案:我只需要放
echo '<tr>';
echo '</tr>';
outside the while! 外一会儿!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.