[英]Save a php variable when a link is clicked
I have this code: 我有这个代码:
$raw_results =
mysql_query("SELECT * FROM student WHERE (`idStudent` LIKE '%".$query."%') OR (`FirstName` LIKE '%".$query."%')");
if(mysql_num_rows($raw_results) > 0)
{
while($results = mysql_fetch_array($raw_results))
{
echo "<tr align='center' bgcolor='#0f7ea3'>
<td height='25px'><a href ='editRegistration.php'> "
.$results['idStudent']."</td> <td>".$results['FirstName']."</td>
</tr>" ;
}
What I want is to store the value of clickable link in to a php variable, so I could send it to aother page. 我想要的是将可点击链接的值存储到php变量中,所以我可以将它发送到另一个页面。 How do I do that?
我怎么做? Thank you
谢谢
You may reform the link printing as: 您可以将链接打印改为:
"<a href ='editRegistration.php?id=".$results['idStudent']."'> ".$results['idStudent']."</a>" ;
This will send you to the editResgistration.php with "id"-GET value. 这会将您发送到带有“id”-GET值的editResgistration.php。 In your editRegistration.php you can get the value by:
在editRegistration.php中,您可以通过以下方式获取值:
$id = $_GET['id'];
You can set whatever you like as query parameter sin a link. 您可以设置任何您喜欢的查询参数sin链接。 Ie
即
echo "<tr align='center' bgcolor='#0f7ea3'>
<td height='25px'><a href ='editRegistration.php?id=" . $results['idStudent'] . "'>"
. $results['idStudent'] . "
</td>
<td>".$results['FirstName']."</td>
</tr>" ;
THen your editRegistration.php can read the student's ID from $_GET['id']
. 您的editRegistration.php可以从
$_GET['id']
读取学生的ID。
(This assumes your ids are numbers or similar and do not need url encoding) (这假设你的id是数字或类似的,不需要url编码)
You can put it this way. 你可以这样说。 And in
editRegistration.php
page, use $ _GET ['id']
在
editRegistration.php
页面中,使用$ _GET ['id']
echo "<tr align='center' bgcolor='#0f7ea3'>
<td height='25px'>
<a href ='editRegistration.php?id=" . $results['idStudent'] . "'>"
. $results['idStudent'] . "
</td>
<td>".$results['FirstName']."</td>
</tr>" ;
editRegistration.php
editRegistration.php
$_GET['id'];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.