简体   繁体   English

如何使我的锚标签从桌子上转移信息?

[英]How can I make my anchor tag transfer information from my table?

I have an anchor tag that displays a users name and clicked it is supposed take you to their profile page. 我有一个显示用户名的锚标记,然后单击它可以将您带到他们的个人资料页面。 I created a form with a post method that I need for accessing that users profile. 我创建了带有post方法的表单,该表单是我访问该用户个人资料所需的。 How can I make the anchor tag act as the form? 如何使锚标签充当表单?

I need the post method with the form to access that user's profile page. 我需要带有表单的post方法来访问该用户的个人资料页面。 $post is a varaible from a foreach loop. $ post是foreach循环中的变量。

<a href = "profiles.php"  id = "name1"><h1>'.$post["UserID"].'</h1></a> 
<form action = "profiles.php"  method = "POST" >
    <input type="submit" class="post id= "nameid" name="id" value= "'.$post["UserID"].'">
</form>

Unless you handle the link with client-side code instead of just letting it be a link, you can't. 除非您使用客户端代码处理链接,而不仅仅是让它成为链接,否则您将无法这样做。

The anchor will send a GET request, while your form is sending a POST request. 当您的表单正在发送POST请求时,锚将发送GET请求。

If you're okay with that, you can append the user id to the query string in the href. 如果可以,可以将用户ID附加到href中的查询字符串中。

'<a href="profiles.php?id='.$post["UserID"].'" id="name1"><h1>'.$post["UserID"].'</h1></a>'

Then you can get the id from $_GET['id'] in profiles.php. 然后,您可以从profiles.php中的$_GET['id']获取ID。 That may not be what you want to do if you don't want the user id in the URL. 如果您不想在URL中输入用户ID,那可能就不是您想要的。 In my opinion would be fine though, and maybe even preferable. 我认为这会很好,甚至更可取。 That would make it easier for a user to bookmark their profile. 这将使用户更容易为他们的个人资料添加书签。

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

相关问题 如何将麦克风声音传输从我的电脑网站打开到其他电脑打开的网站? - how can i make microphone sound transfer from website open in my pc to websites open in others pc? 如何使用锚标记href打开代码的详细信息数据? - How I can use anchor tag href to open details data for my code? 我如何增加我的 <p> 我单击时添加标签添加到我的HTML表格中? - How can I increment my <p> tag when I clicked add in my HTML table? 如何使数据库图像显示在表中? - How can I make my DB images be displayed in the table? 如何使导出文件导出更大的表 - How can I make my export file export a bigger table 如何从表中选择数据并使其成为字符串? - How do I select data from my table and make it a string? PHP-为什么我不能在表中插入信息? - PHP - Why can't I insert information into my table? 如何将数据行ID从格式化程序转移到模态下,以便我可以处理适当的记录 - How do I transfer the data-row-id from my formatter to my modal so I can process the proper record 如何使我的主题/发送者使用我制作的某些标签 - How to make my subject/sender work with some tag i make 我怎样才能让我的单选复选框在我的表格中每行只允许一个检查 - How can I make my radio checkbox's only be allowed one check per row in my table
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM