我想通过其启动会话的代码如下:
$user = mysqli_fetch_array($run);
$run1 = mysqli_query($conn,"select * from users where email='$email' AND school_id='$school_id'");
$users = array();
while($user_r = mysqli_fetch_array($run1))
{
$users[] = array("subject_id" => $user_r['subject_id'],"class_id" => $user_r['class_id']);
$_SESSION['sub_cls']=$users;
}
但是我无法启动会话并且它不会返回任何值。 我应该如何开始会议?
答案 0 :(得分:2)
<?php
session_start();
$user = mysqli_fetch_array($run);
$run1 = mysqli_query($conn,"select * from users where email='$email' AND school_id='$school_id'");
$users = array();
while($user_r = mysqli_fetch_array($run1))
{
$users[] = array( "subject_id" => $user_r['subject_id'], "class_id" => $user_r['class_id'] );
}
// create session, here we stored session in sub_cls variable
$_SESSION['sub_cls'] = $users;
读取read_session.php中的会话值
<?php
session_start();
echo $_SESSION['sub_cls']['subject_id'];
echo $_SESSION['sub_cls']['class_id'];
?>