我有一个表(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>"; ?>
更多推荐
发布评论