为 PHP While 循环表中的每个 TD 分配一个链接

发布于 2024-10-10 00:59:06 字数 461 浏览 0 评论 0原文

我有一个 while 循环从 mysql 数据库检索信息。现在有一个名为配置文件的栏目。因此,我希望配置文件中的每个 都是一个按钮,该按钮具有会导致打开 PHP 页面的操作。我该怎么做?

<form action="profile.php" method="get">

while($result)
{
echo '<table>';
echo '<tr>';
echo '<td>';
echo $result['profile'];
echo '</tr>';
echo '</td>';
echo '</table>';
}

现在每个 $result['profile'] 都应该是一个类似的提交 -

谢谢。

I have a while loop that retrieves info from the mysql db. Now there is a column called profile. So I want every <td> in the profile to be a button that would have an action which would lead to a PHP page. How do I do that?

<form action="profile.php" method="get">

while($result)
{
echo '<table>';
echo '<tr>';
echo '<td>';
echo $result['profile'];
echo '</tr>';
echo '</td>';
echo '</table>';
}

Now every $result['profile'] should be a submit like - <input type="submit">

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

罪歌 2024-10-17 00:59:06

重写

echo $result['profile'];

这段代码:

echo '<a href="profile.php?id='.$result['id'].'">'.$result['name'].'</a>' ;

rewrite

echo $result['profile'];

to this code:

echo '<a href="profile.php?id='.$result['id'].'">'.$result['name'].'</a>' ;
千纸鹤带着心事 2024-10-17 00:59:06

首先,

echo '</tr>';
echo '</td>';

应该是:

echo '</td>';
echo '</tr>';

要添加提交按钮,请更改

echo '<td>';

echo '<td><input type="Submit" value="Submit">';

echo '</td>';

to

echo '</input></td>';

您将需要向提交按钮添加适当的属性(如果适用)。此外,您还需要用 form 元素包围提交按钮。每个链接是否都有自己的形式,或者整个表格都被一个链接包围,这取决于您。

编辑

要使用 form 标记包围表格,请将 echo ''; 更改为 echo '

; <表>';。然后,将 echo '

'; 更改为 echo '';。提交按钮会自动“链接”到它们所包含的 form 元素。您所要做的就是定义表单 action

编辑

实际上,因为您使用的是 GET 请求,所以可以通过使用链接而不是表单来简化整个事情。所以就用 RAMe0 的答案吧。

First of all,

echo '</tr>';
echo '</td>';

should be:

echo '</td>';
echo '</tr>';

To add a Submit button, change

echo '<td>';

to

echo '<td><input type="Submit" value="Submit">';

and

echo '</td>';

to

echo '</input></td>';

You will need to add the appropriate attributes to the submit button if applicable. Also, you will need to surround the submit button with a form element. Whether each link has its own form, or the entire table is surrounded by one is up to you.

Edit

To surround the table with a form tag, change echo '<table>'; to echo '<form><table>';. Then, change echo '</table>'; to echo '</table></form>';. Submit buttons are automatically "linked" to the form element they are contained in. All you have to do is to define the form action.

Edit

Actually, because you are using a GET request, this entire thing can be simplified by using links instead of forms. So go with RAMe0's answer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文