我有一个页面来获取用户event_id,然后该页面用于从mysql中检索所有user_id和与该event_id相关的信息。然后,将数据显示在表中,其中一行代表一个用户。因此,现在,当用户在另一个页面中单击该用户时,我想显示该用户的其他信息。
这是代码示例,用于说明我正在尝试的工作。代码可能不如实际代码太长而无法显示。
main.php
<form name="input" method="post">
<input type="text" id="event_id" name = "event_id" value = "" /><br>
<input type="submit" name="Submit" value="Submit" />
</form>
//$user_main is an associative array generated when event_id
//is entered into input text box and user click submit
<?php $user_main = array(); ?>
<table>
<?php
//Loop through and print all user_id associated with event_id entered
foreach(user_main as main)
{ ?>
<tr>User ID: <?php echo $main['user_id'];?></tr>
<tr>User Name: <?php echo $main['user_name'];?></tr>
<tr>User Info: <a href = "display.php">Contact</a></tr>
<?php } ?>
</table>
display.php
//Pass user_id to display.php page that correspond to the user id clicked
user_id = {{ 111 }}
//retrieve contact info from mysql for user_id = 111 and display below
<table>
<tr>User ID: </tr>
<tr>Mobile: </tr>
<tr>Address: </tr>
<tr>Email: </tr>
</table>
我的问题是如何将变量传递到另一个页面。例如,如果用户单击user_id = 111的链接,如何将值“ 111”传递到display.php页面,以便可以从mysql检索数据以显示信息?
对于此类任务,URI参数非常常用。$_GET
在这种情况下,您可以使用超全局变量。
<tr>User Info: <a href = "display.php?userid=<?php echo $main['user_id'];?>">Contact</a></tr>
在你的display.php
你就可以像这样访问的变量:
<?php
echo $_GET['userid'];
从现在开始应该很清楚。您可以根据$_GET
数据获取记录。不要忘记在此处添加额外的安全性。您永远不应信任用户输入。
这是非常基础的东西,因此,我建议您对超全局变量有所了解,直到您感到自信为止。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句