简体   繁体   English

我正在尝试将数据库中的所有列打印到水平表

[英]I'm trying to print all columns in database to a horizontally table

I know I did something so stupid in my code but please help me .我知道我在我的代码中做了一些非常愚蠢的事情,但请帮助我。 As you see I'm trying to print all the information in database horizontally and when I run this, it only grabs client and doesn't grab the other columns from database.正如你所看到的,我试图水平打印数据库中的所有信息,当我运行它时,它只抓取客户端而不抓取数据库中的其他列。 I hope all the information I gave you is enough.我希望我给你的所有信息都足够了。

<table>
    <?php       $query = "SELECT * FROM 1d ORDER BY 'client' DESC";
                $result = mysqli_query($conn, $query); ?>
    <tbody>
        <tr>
            <th rowspan="6" style="color:black;font-size:30;width: 5%;height:400px;background-color:white;"><p style="width:100px;white-space: nowrap;position: relative;right:50%;white-space: nowrap;    top: 57px;transform-origin: right;transform: rotate(-90deg);">1D : Preparation</p><br></th>
            <th style="width:200px;">Client</th>
            <?php while($row = mysqli_fetch_assoc($result)){ ?>
            <td ><?php echo $row['client']; ?></td>
            <?php } ?>
        </tr>
        <tr>
            <th >Produit</th>
            <?php while($row = mysqli_fetch_assoc($result)){ ?>
            <td ><?php echo $row['produit']; ?></td>
            <?php } ?>
        </tr>
        <tr>
            <th >Equipe</th>
            <?php while($row = mysqli_fetch_assoc($result)){ ?>
                <td ><?php echo $row['equipe']; ?></td>
            <?php } ?>
        </tr>
        <tr>
            <th >Date</th>
            <?php while($row = mysqli_fetch_assoc($result)){ ?>
                <td ><?php echo $row['pdate']; ?></td>
            <?php } ?>
        </tr>
        <tr>
            <th >Description de Probleme</th>
            <?php while($row = mysqli_fetch_assoc($result)){ ?>
                <td ><?php echo $row['descdpro']; ?></td>
            <?php } ?>
        </tr>
        <tr>
            <th >Pilote</th>
            <?php while($row = mysqli_fetch_assoc($result)){ ?>
                <td ><?php echo $row['pilote']; ?></td>
            <?php } ?>
        </tr>
    </tbody>
</table>

mysqli_fetch_assoc iterate throug the $result variable one time. mysqli_fetch_assoc 遍历$result变量一次。 After the first cycle the others get false and you cannot see other elements than the first.在第一个循环之后,其他元素变为假,除了第一个之外,您看不到其他元素。

To avoid this you can populate an array with the results:为避免这种情况,您可以使用结果填充数组:

<?php
    $query = "SELECT * FROM 1d ORDER BY 'client' DESC";
    $result = mysqli_query($conn, $query);
    $results = array();
    while($row = mysqli_fetch_assoc($result)){
        $results[] = $row;
    }
?>

and change every cycle with this:并用这个改变每个周期:

<?php foreach($results as $row){ ?>
     <td ><?php echo $row[ ... insert the key here ...]; ?></td>
<?php } ?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我正在尝试将 AJAX 应用于我的 tbody,而不是所有表 - I'm trying to apply AJAX to my tbody only not all table 我正在尝试为注册的每个用户创建一个数据库表。 我究竟做错了什么? - I'm trying to create a database table for each user who registers. What am I doing wrong? 我正在尝试更新我的MySQL数据库 - I'm trying to update my mysql database 我正在尝试将MySQL数据库中的数据显示到HTML表上,但未注册列字段 - I'm trying to display data from a MySQL database onto an HTML table but doesn't register the column fields 我正在尝试在PHP的无序列表中打印所有数据库用户。 但这不起作用 - I am trying to print all the database users in a Unordered list in PHP. But it is not working 尝试从这里获取多列的平均值,但所有值都打印为0 - Trying to get averages from multiple columns here but all the values print as 0 在数据库sql中的所有表列中搜索一个字符串 - Search for a string in all table columns in database sql 我正在尝试在表中显示数据库中的数据,但不想出现,也不知道出了什么问题 - I'm trying to display data from my database in table, but don't want to appear, I don't know what went wrong 我正在尝试更改数据库中的表,但是当我尝试更改列数据时显示但不在其他数据的同一行中? - I'm trying to alter a table in a database but when I try altering the column data is displayed but not in the same row of the the other data? 到目前为止,我正在尝试使用PHP在数据库上创建表,但是我设法使用PHP创建了数据库,但无法创建表/表 - I'm trying to create a table on my database using PHP so far i have managed to create a database using PHP but but fail to create table/tables
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM