在html表中显示mysql行 [英] Display mysql rows in html table

查看:59
本文介绍了在html表中显示mysql行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以这是我到目前为止所做的:http://d.pr/i/c6z

So here is what I did so far: http://d.pr/i/c6z

代码:

<tbody>
<?php while ($row = mysql_fetch_assoc($result)): ?>
    <tr>
        <td><?php echo $row['id']; ?></td>
        <?php foreach ($row as $key): ?>
        <td><a href="#"><?php echo $key; ?></a></td>
        <?php endforeach; ?>
    </tr>
<?php endwhile; ?>
</tbody>

我的 mysql 表如下所示:id (PRIMARY KEY)、全名、​​用户名.如您所见,我想要做的是在 html 表中显示所有这些记录,但我不想要的是第一列中的 href 链接,只是一个数字.SSo,如何在 foreach 循环中删除数组中的第一个值,即id",或者可能有更好的方法来做这件事?

and my mysql table looks like that: id (PRIMARY KEY), fullname, username. As you can see, what i'm trying to do is to display all of these records in html table, but what I don't want is href link in first column, just a numbers. SSo, how to remove in foreach loop the first value from the array which is 'id' or maybe there is a better way to do this thing?

推荐答案

试试这个:

<tbody>
<?php while ($row = mysql_fetch_assoc($result)): ?>
    <tr>
        <?php foreach ($row as $key): ?>
            <?php if($key === 'id'): ?>
               <td><?php echo $row['id']; ?></td>
            <?php else: ?>
               <td><a href="#"><?php echo $key; ?></a></td>
            <?php endif; ?>
        <?php endforeach; ?>
    </tr>
<?php endwhile; ?>
</tbody>

两个不同的视图,所以你有两个条件.一个视图更容易阅读.

Two different views so you have two conditions. It is easier to read for a view.

这篇关于在html表中显示mysql行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆