简体   繁体   English

PHP,HTML和MySqli-如何在一个表行中显示特定列的所有数据

[英]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.

相关问题 如何在PHP Codeigniter中从一个表中获取特定列,并从另一表中获取所有其他数据 - How to get specific column from one table and all other data from other table in php codeigniter 查询数据库后如何从数组调用特定的行和列数据…(mysqli php) - How do i call specific row and column data from an array after querying a database… (mysqli php) 如何使用php和mysqli将数据插入数据库中动态创建的表(html)行中 - how to insert data into a dynamically created row in a table (html) from database using php and mysqli 使用php拉特定的表行列数据以html输出 - pull specific table row column data to output in html using php php从所有行的同一列中获取特定数据 - php get specific data from the same column in all row PHP MySQLi 如何在 html 表中显示用户个人资料图像? - PHP MySQLi How to show user profile image in html table? 如何在mysqli表列中一个接一个地列出所有相关数据 - How do i list out all related data in mysqli table column one after the other 如何使用MySQLI vs MySQL显示数据库中特定表行列的数据 - How to display data from specific table row columns in the database with MySQLI vs MySQL 在特定表列上显示PHP在MySQL上的行内容(不同表上的.row名称相同) - Show MySQL row content on PHP from specific table column (same .row name on different tables) 如何从表中获取所有数据,如果在同一列中重复相同的值,则该行应计数一次? - How to get get all the data from table and if same value repeated in one column that row should count once?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM