-1

我有一个学校网络应用程序..我想在 $_SESSION['allStudent'] 的 log_in.php 页面上获取所有学生姓名,以便在其他页面上检索...

这是我登录的 .php 页面内容

    include("connect.php");
    if(isset($_REQUEST['submit']))
    {
$id=$_REQUEST['userName'];
$pass=$_REQUEST['password'];

$sel=mysql_query("select * from login_detail where USERNAME='$id' AND  PASSWORD='$pass'")or die(mysql_error());
if($arr=mysql_fetch_array($sel))
{

    if(($id==$arr['USERNAME']) && ($pass==$arr['PASSWORD']))
    {
        session_start();
        $_SESSION['id']=$id;

        $query = "SELECT * FROM student_personal";
        $result = mysql_query($query) or die(mysql_error());
        if($result)
        {
            $_SESSION['allStudent']['']= mysql_fetch_array($result);
        }
        header("location: viewPages/common/main.php?active=dashboard");
    }
     }
      else
     {
echo "<script>alert('please enter the correct  id and password');</script>";
   }
    }

并检索到主页这是我的主页

           {
           //designed Part
          }
        <?php
    if(isset($_SESION['allStudent']))
    {
    echo "------------------------------------------<br>";
    echo "Student Name--------------------------- DOB<br>";
    echo "------------------------------------------<br>";
    while($row = mysql_fetch_array($_SESSION['allStudent']))
    {   

    echo $row['STUDENT_NAME']." --------------".$row['DOB']."<br>";

    }
        }
        else
         {
       echo "No result Found";
         }  
        ?>

这是我的桌子

       DB NAME : testssdb
       Table Name : student_personal

       `SR_NUMBER` int(11) NOT NULL,
       `STUDENT_NAME` varchar(30) NOT NULL,
       `GENDER` int(11) NOT NULL,
       `DOB` varchar(25) NOT NULL,
       `RELIGION` varchar(30) NOT NULL,
      `MAILING_ADDRESS` text NOT NULL,
       `TELEPHONE_NO` varchar(22) default NULL,
       `MOBILE_NO` varchar(25) default NULL,
      `EMAIL` varchar(30) default NULL,
      `PERMANENT_ADDRESS` text,
      `MOTHER_TONGUE` varchar(30) default NULL,
      `CATEGORY` int(11) default NULL,
      `STATUS` int(11) NOT NULL default '1',
      `REG_DATE` date NOT NULL,
      `FIRST_NAME` varchar(25) NOT NULL,
      `LAST_NAME` varchar(25) NOT NULL,
      PRIMARY KEY  (`SR_NUMBER`)




这里 $student = $firstname.$lastName; 所以基本上我想在登录和任何学生时存储所有学生记录,我不想与数据库联系。只使用会话我得到学生信息

4

1 回答 1

2
session_start();

    $_SESSION['count'] = 1;

    $_SESSION['record'][$_SESSION['count']] = array();

    $query //retrive ur data here
    $result set of ur query
    while ($row = mysql_fetch_assoc($result))
    {

    $_SESSION['record'][$_SESSION['count']]['SR_NUMBER'] = $row["SR_NUMBER"];
    $_SESSION['record'][$_SESSION['count']]['STUDENT_NAME'] = $row["STUDENT_NAME"];
    $_SESSION['record'][$_SESSION['count']]['GENDER'] = $row["GENDER"];
    $_SESSION['record'][$_SESSION['count']]['DOB'] = $row['DOB'];
    ...// and go on

    $_SESSION['count'] = $_SESSION['count'] + 1;
    }

    foreach($_SESSION['record'] as $key => $value)
    {
        echo $value['SR_NUMBER'];
        echo $value['STUDENT_NAME'];
        echo $value['GENDER'];
        echo $value['DOB'];
        ....
    }
于 2013-09-02T13:04:05.493 回答