PHP MYSQL:如何保持变量活动直到连接结束
我想保持一些变量处于活动状态,以便网站的所有页面都可以使用它; 我尝试了全局,但这不适用于此类问题; 我使用以下代码:
while($result1 = mysql_fetch_array( $result))
{
$adm_no = $result1['adm_no'];
$adm_dt = $result1['adm_dt'];
$name = $result1['name'];
$dob = $result1['dob'];
$f_name = $result1['f_name'];
$f_office = $result1['f_office'];
$f_o_no = $result1['f_o_no'];
$m_name = $result1['m_name'];
$m_office = $result1['m_office'];
$addr = $result1['addr'];
$pho_no = $result['pho_no'];
另一个名为 tc.php 的页面中的相同变量。我该怎么办?
i want to keep some variable alive so that it is available to all the pages of the site ;
i tried global but that don't work with these kind of problem ;
i use the following code :
while($result1 = mysql_fetch_array( $result))
{
$adm_no = $result1['adm_no'];
$adm_dt = $result1['adm_dt'];
$name = $result1['name'];
$dob = $result1['dob'];
$f_name = $result1['f_name'];
$f_office = $result1['f_office'];
$f_o_no = $result1['f_o_no'];
$m_name = $result1['m_name'];
$m_office = $result1['m_office'];
$addr = $result1['addr'];
$pho_no = $result['pho_no'];
these same variable in another page called tc.php . how can i do that ????
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您想在另一个页面中再次访问所有数据,我建议您存储在会话中从 mysql 表检索数据所需的信息,而不是查询结果。这意味着您的会话空间中没有大量琐碎的数据。例如。
想象一下,我有一个人员表,想要在不同页面上获取该人员的信息,我只需将 person_id 存储在会话中,如下所示:
然后在任何我想要检索人员信息的页面上,我只需从会话中获取人员 id并运行查询以获取我需要的特定信息。
如果你真的无法改变你这样做的方式,我真的希望你可以,因为它会让你的生活变得更加轻松,那么只需将你的代码更改为:
If you want to access all that data again in another page I would recommend storing the information needed to retrieve data from your mysql table in a session rather than the result of the query. This means you don't have a load of trivial data in your session space. For example.
Imagine I have a person table and want to get bits of information for that person on different pages I just store the person_id in a session like so:
Then on any page I want to retrieve person information on I just get the person id from the session and run the query to get the specific information I need.
If you really cant change the way that you are doing this which I really hope you can as it'll make your life a hell of a lot easier then just changing your code to this:
使用
will可以访问任意页面
Use
will can access any page
在 tc.php 中再次获取数据 - 我认为这是这种情况下最好的方法。
您还可以将该数据设置到会话中,并在 tc.php 中从那里获取它。
Fetch data again in
tc.php
- it is the best way in this case I think.You can also set that data to the session, and in
tc.php
get it from there.