为 PHP While 循环表中的每个 TD 分配一个链接
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
重写
这段代码:
rewrite
to this code:
首先,
应该是:
要添加提交按钮,请更改
为
和
to
您将需要向提交按钮添加适当的属性(如果适用)。此外,您还需要用
form
元素包围提交按钮。每个链接是否都有自己的形式,或者整个表格都被一个链接包围,这取决于您。编辑
要使用
form
标记包围表格,请将echo ''; 更改为
echo '
; <表>';
。然后,将echo '
';
更改为echo '';
。提交按钮会自动“链接”到它们所包含的form
元素。您所要做的就是定义表单action
。编辑
实际上,因为您使用的是 GET 请求,所以可以通过使用链接而不是表单来简化整个事情。所以就用 RAMe0 的答案吧。
First of all,
should be:
To add a Submit button, change
to
and
to
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, changeecho '<table>';
toecho '<form><table>';
. Then, changeecho '</table>';
toecho '</table></form>';
. Submit buttons are automatically "linked" to theform
element they are contained in. All you have to do is to define the formaction
.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.