如何使用PHP和mysql通过id打开新页面?(How can I open a new page by id using PHP and mysql?)

编程入门 行业动态 更新时间:2024-10-24 22:21:34
如何使用PHP和mysql通过id打开新页面?(How can I open a new page by id using PHP and mysql?)

我有一个表(mysql):可选表标题。

<table class="table"> <caption>myTable</caption> <thead> <tr> <th>ID</th> <th>First Name</th> <th>Last Name</th> <th>Username</th> </tr> </thead> <tbody> <tr> <th scope="row">1</th> <td>Mark</td> <td>Otto</td> <td>@mdo</td> </tr> <tr> <th scope="row">2</th> <td>Jacob</td> <td>Thornton</td> <td>@fat</td> </tr> <tr> <th scope="row">3</th> <td>Larry</td> <td>the Bird</td> <td>@twitter</td> </tr> </tbody> </table> 
  
 

我有一个persons.php页面,从该表中提取所有人的姓名,并显示如下:

<div>
    <p>Name: Mark Otto <a href="#">View</a></p>
  <p>Name: Jacob Thornton <a href="#">View</a></p>
  <p>Name: Larry the Bird <a href="#">View</butaon></p>
 </div> 
  
 

我有一个详细的.php来显示人的用户名,如下所示:

<div>
  <p>ID: ?</p>
  <p>First name: ?</p>
  <p>Last name: ?</p>
  <p>User name: ?</p>
 </div> 
  
 

我的问题是如何在点击“查看”链接时按ID获取detailed.php页面?

对不起,我正在学习PHP,我的观点是当点击查看链接时,有什么方法可以获得ID显示的详细信息。 我知道如何在使用php + mysql时显示数据,但我不知道如何执行点击操作并直接显示通过id显示信息的detailed.php页面。

谢谢!

I have a table (mysql): Optional table caption.

<table class="table"> <caption>myTable</caption> <thead> <tr> <th>ID</th> <th>First Name</th> <th>Last Name</th> <th>Username</th> </tr> </thead> <tbody> <tr> <th scope="row">1</th> <td>Mark</td> <td>Otto</td> <td>@mdo</td> </tr> <tr> <th scope="row">2</th> <td>Jacob</td> <td>Thornton</td> <td>@fat</td> </tr> <tr> <th scope="row">3</th> <td>Larry</td> <td>the Bird</td> <td>@twitter</td> </tr> </tbody> </table> 
  
 

I have a persons.php page that pull out all person's name from that table, and showing like this:

<div>
    <p>Name: Mark Otto <a href="#">View</a></p>
  <p>Name: Jacob Thornton <a href="#">View</a></p>
  <p>Name: Larry the Bird <a href="#">View</butaon></p>
 </div> 
  
 

And I have a detailed.php that shows person's username, like this:

<div>
  <p>ID: ?</p>
  <p>First name: ?</p>
  <p>Last name: ?</p>
  <p>User name: ?</p>
 </div> 
  
 

My question is that how to get detailed.php page by id when click the 'View' link?

Sorry, I am learning PHP, my point is when click the view link, what is the way to get the detailed.php displayed by the ID. I know how to get data displayed while using php+mysql, but I don't know how to perform the click action and direct to detailed.php page that showing info by id.

Thanks!

最满意答案

用<a href替换<button 。 在“persons.php”中,你需要在<a href回显ID,稍后在“detailed.php”中,你得到$_GET[ "id" ] :

persons.php

<div> Name: Larry the Bird <a href="detailed.php?id=<?php echo $id;?>">View</a>

detailed.php

<?php if ( isset( $_GET[ "id" ] ) ) echo "<p>ID: " . $_GET[ "id" ] . "</p>"; ?>

Replace the <button by <a href. In "persons.php" you will need to echo the ID in the <a href, later, in "detailed.php", you get the value as $_GET[ "id" ]:

persons.php

<div> Name: Larry the Bird <a href="detailed.php?id=<?php echo $id;?>">View</a>

detailed.php

<?php if ( isset( $_GET[ "id" ] ) ) echo "<p>ID: " . $_GET[ "id" ] . "</p>"; ?>

更多推荐

本文发布于:2023-07-23 18:46:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1235713.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   新页面   PHP   id   mysql

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!