PHP - 将相同的值传递给多个页面

时间:2012-11-17 18:02:34

标签: php

我有多个页面传递两个值,值为Sname& SID ..

我用过

$sql = "SELECT s.Sname, e.PID , s.SID
                          from student AS s
                          INNER JOIN evaluator AS e                       
                          WHERE (e.EID1 = '$id' AND s.PID = e.PID) OR  (e.EID2 = '$id' AND s.PID = e.PID)
                          GROUP BY s.Sname  ";
         $result = mysql_query ($sql, $connection);

         echo "<tr><th>Student Name </th>";
         echo "<td><select id='Sname' name='Sname' >";

         echo "<option value='' selected='selected'>--</option> ";

        while( $row = mysql_fetch_array($result))
   {

      echo "<option value='$row[SID]|$row[Sname]' >$row[Sname]</option> ";


   }

并在接收页面中添加

 list($SID, $Sname) = explode("|", $_POST['Sname']);

它的工作原理,但对于其他页面,我想要相同的值,我试图把相同的爆炸()但它不起作用..给我一个错误说未定义的索引:Sname +未定义的偏移量: 1 ..我的问题是我怎样才能传递相同的价值Sname&amp;也适用于其他页面?

1 个答案:

答案 0 :(得分:1)

您可以通过会话执行此操作,在要传递的会话中存储值

首先你需要通过

开始会话
<?php //must not any spave before php tag and must be on very first line 
session_start(); 

比您想要的商店值

$_SESSION['views'] = 5;

你可以在你想要的页面上访问

echo "Views=". $_SESSION['views'];