[英]How can I open a new page by id using PHP and mysql?
I have a table (mysql): Optional table caption. 我有一个表(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>
I have a persons.php page that pull out all person's name from that table, and showing like this: 我有一个person.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>
And I have a detailed.php that shows person's username, like this: 我有一个detail.php,它显示人的用户名,如下所示:
<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? 我的问题是,当单击“查看”链接时,如何通过id获取detail.php页面?
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. 抱歉,我正在学习PHP,我的意思是单击视图链接时,通过ID获取显示detail.php的方法是什么。 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.
我知道如何在使用php + mysql时获取显示的数据,但是我不知道如何执行单击操作并直接转到通过id显示信息的detail.php页面。
Thanks! 谢谢!
Replace the <button
by <a href
. 将
<button
替换为<button
<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”中,您将需要在
<a href
回显ID,稍后在“ detailed.php”中,您将获得$_GET[ "id" ]
:
persons.php person.php
<div>
Name: Larry the Bird <a href="detailed.php?id=<?php echo $id;?>">View</a>
detailed.php detail.php
<?php
if ( isset( $_GET[ "id" ] ) )
echo "<p>ID: " . $_GET[ "id" ] . "</p>";
?>
Try this! 尝试这个! put your query instead of'$yourquery'
放置您的查询,而不是“ $ yourquery”
<?php
<table>
<thead>
<tr>
<th># </th>
<th>Name</th>
<th>Action</th>
</tr>
</thead>
<tbody>
while($row=mysql_fetch_array($yourquery))
{
?>
<tr>
<td>Name : <?=$row['name']?> <?=$row['lastname']?></td>
<form method="GET" action="detailed.php">
<input type="hidden" value="<?=$row['id']?>" name="id" />
<td><button type="submit">View</button></td>
</form>
</tr>
<?php
}
?>
</tbody>
</table>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.