Mysql + php,如何建立一个链接,当您按“标题"时,该链接显示一条记录中的所有数据. [英] Mysql+php, how to make a link that shows all data from a record when you press the "headline"
问题描述
正如标题所述,这可能不是一个问题,更多地是提示操作方法.
As the title says, and this is not probably a question, more a hint how to do it.
我的表格包含四个字段, id(自动+主),名字,姓氏,年龄
I have table with four fields, id (auto+primary), firstname, lastname, age.
在索引页面上,我选择*,然后将名字设为指向该页面的链接的链接,该页面要显示该记录的所有数据.
On my index page I select *, then I make the firstname to a link which goes to antoher page which I want to show all data for that record.
目前,我必须手动执行从* where id ="2"中选择*". (另一页)
For the moment I have to do it manually "select * from " where id="2". (the other page)
如何建立链接以自动检测该记录集中的ID",并仅显示该记录中的数据.
How do I make the link to autodetect "the id from that record set" and only display data from that record.
您可以在这里看到我的当前项目,
You can see my curreny project here,
http://www.adamskymotorkylare.se/business/
如您所见,当您单击名字"时,它将始终在id = 2(paris hilton)处显示我想要的数据,当我单击"jack"时,它将在id处选择* ="1"
as you can see, when you click the "firstname" it will always display data where id=2 ( paris hilton ), what I want it to do, it when I click "jack" it will select * from where id="1"
杰克,谢谢你
索引页"
$result = mysqli_query($con,"SELECT * FROM persons");
echo "<table width=100%>
<tr>
<th>ID</th>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
<th>Gender</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
$id = $row['id'];
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td> <a href='view_more.php?id= . $id .'>" . $row['firstname'] . "</a> </td>";
echo "<td>" . $row['lastname'] . "</td>";
echo "<td>" . $row['age'] . "</td>";
echo "<td>" . $row['gender'] . "</td>";
echo "</tr>";
}
echo "</table>";
查看更多页面"
$id = $_get['id'];
$result = mysqli_query($con,"SELECT * FROM persons
WHERE id='$id'");
echo "<table width=100%>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
<th>Gender</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td> <a href='#'>" . $row['firstname'] . "</a> </td>";
echo "<td>" . $row['lastname'] . "</td>";
echo "<td>" . $row['age'] . "</td>";
echo "<td>" . $row['gender'] . "</td>";
echo "</tr>";
}
echo "</table>";
推荐答案
在为用户建立索引的页面上尝试以下操作:
Try this, on your page that indexes the users:
while($row = mysqli_fetch_array($result))
{
$id = $row['id'];
$firstName = $row['firstName'];
echo ('<a href="user_account.php?id=' . $id . '">' . $firstName . '</a>');
}
这意味着如果有人单击名字,他们将被发送到user_account.php(可以替换为明显的名字),您将通过URL(user_account.php?id = 123)传递ID.
This means if someone clicks the first name they will be sent to user_account.php (can replace this obviously) and you will pass in the ID via the URL (user_account.php?id=123).
在用户帐户"页面上,您需要执行以下操作:
On the User Account page you want to do the following:
// GET ID FROM THE URL
$id = $_GET['id'];
$result = mysqli_query($con,"SELECT (WHATEVER YOU WANT) FROM (YOUR TABLE) WHERE id = $id");
注意: 替换变量并查询所需的详细信息.
Notes: Replace variables and query with the details you need.
我希望能有所帮助.
这篇关于Mysql + php,如何建立一个链接,当您按“标题"时,该链接显示一条记录中的所有数据.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!