我创建了一个在线注册系统。我已经制作了一份无序列表,以显示等待批准或拒绝的新待审申请人。我还为每个新申请人添加了一个按钮,以显示待处理表中的数据。
问题是当我添加多个申请人时,它只会显示所有申请人的最后申请人详细信息。我已经经历了好几个小时,但几天没有任何作用。
这是我的代码来自具有无序列表的页面:
function getStudent () {
global $conn;
$query = "SELECT * FROM pending_students_table WHERE status IS NULL;";
$result = mysqli_query($conn, $query);
$i = 1;
while ($row = mysqli_fetch_array($result)) {
$sId = $row['id'];
$sName = $row['student_name'];
$_SESSION['id'] = $row['id'];
echo "<tr id='sNew".$i."'>";
echo "<td>".$i." - </td>";
echo "<td>{$sName}</td>";
echo "<td><button type='submit' name='sAcc' value='{$sId}'>Accept</button></td>";
echo "<td><button type='submit' name='sRej' value='{$sId}'>Reject</button></td>";
echo "<td><button name='stInfo' value='{$sId}'><a href='student_information.php?id=<?php echo ".'"$row[$id]"'."; ?>' target='_blank' style='color: #000000; text-decoration: none;' onClick='pop_up(this)'>Student Details</a></button></td>";
echo "</tr>";
$i++;
}
}
这是来自student_information.php的代码:
<?php
session_start();
include ('partials/connectDb.php');
echo "<h2>Student Information</h2>";
$id = $_SESSION['id'];
$sql = "SELECT pending_students_table.id, pending_students_table.student_name,
pending_students_table.student_email, pending_students_table.student_phone,
major_table.major_name, pending_students_table.student_password,
pending_students_table.high_school_major, pending_students_table.high_school_gpa,
pending_students_table.adviser, pending_students_table.status
FROM pending_students_table INNER JOIN major_table ON pending_students_table.student_major = major_table.major_id WHERE pending_students_table.id = '$id';";
$result = mysqli_query($conn, $sql);
while($row = mysqli_fetch_array($result)) {
$sId = $row['id'];
$sName = $row['student_name'];
$sPhone = $row['student_phone'];
$sMajor = $row['major_name'];
$sHsMajor = $row['high_school_major'];
$sHsGpa = $row['high_school_gpa'];
$sHsMajorString = '';
if ($sHsMajor == 1) {
$sHsMajorString = 'Commercial';
} elseif ($sHsMajor == 2) {
$sHsMajorString = 'Literature';
} elseif ($sHsMajor == 3) {
$sHsMajorString = 'Science';
} elseif ($sHsMajor == 4) {
$sHsMajorString = '(Institute of Technology)';
}
echo "<ul>";
echo "<li>Name: {$sName}</li>";
echo "<li>Phone: {$sPhone}</li>";
echo "<li>Selected Major: {$sMajor}</li>";
echo "<li>High School Major: {$sHsMajorString}</li>";
echo "<li>High School GPA: {$sHsGpa}</li>";
echo "</ul>";
}
?>
答案 0 :(得分:0)
您在students_information.php中使用$ _SESSION ['id'],这始终是最后查询的学生。
解决方案:
使用$ _GET变量:
$id = $_GET['id'];
第二个问题:
创建链接时,添加另一对不需要的链接。所以要么按照我的评论中的建议替换它们,要么使用
str_replace("'","")
答案 1 :(得分:0)
在您对student_information.php的链接中,您使用内联PHP代码,但您已经在解析区域中。
因此,您不必使用href='student_information.php?id=<?php echo ".'"$row[$id]"'."; ?>' target='_blank'
,即可使用href='student_information.php?id=$row['id']' target='_blank'
。
更改代码:
function getStudent () {
global $conn;
$query = "SELECT * FROM pending_students_table WHERE status IS NULL;";
$result = mysqli_query($conn, $query);
$i = 1;
while ($row = mysqli_fetch_array($result)) {
$sId = $row['id'];
$sName = $row['student_name'];
$_SESSION['id'] = $row['id'];
echo "<tr id='sNew".$i."'>";
echo "<td>".$i." - </td>";
echo "<td>{$sName}</td>";
echo "<td><button type='submit' name='sAcc' value='{$sId}'>Accept</button></td>";
echo "<td><button type='submit' name='sRej' value='{$sId}'>Reject</button></td>";
echo "<td><button name='stInfo' value='{$sId}'><a href='student_information.php?id=".$row['id']."' target='_blank' style='color: #000000; text-decoration: none;' onClick='pop_up(this)'>Student Details</a></button></td>";
echo "</tr>";
$i++;
}
}
此外,您应该使用$id = $_GET['id'];
代替$id = $_SESSION['id'];
,因为$_SESSION['id'];
将始终包含最后一个ID。
更改代码:
<?php
session_start();
include ('partials/connectDb.php');
echo "<h2>Student Information</h2>";
$id = $_GET['id'];
$sql = "SELECT pending_students_table.id, pending_students_table.student_name,
pending_students_table.student_email, pending_students_table.student_phone,
major_table.major_name, pending_students_table.student_password,
pending_students_table.high_school_major, pending_students_table.high_school_gpa,
pending_students_table.adviser, pending_students_table.status
FROM pending_students_table INNER JOIN major_table ON pending_students_table.student_major = major_table.major_id WHERE pending_students_table.id = '$id';";
$result = mysqli_query($conn, $sql);
while($row = mysqli_fetch_array($result)) {
$sId = $row['id'];
$sName = $row['student_name'];
$sPhone = $row['student_phone'];
$sMajor = $row['major_name'];
$sHsMajor = $row['high_school_major'];
$sHsGpa = $row['high_school_gpa'];
$sHsMajorString = '';
if ($sHsMajor == 1) {
$sHsMajorString = 'Commercial';
} elseif ($sHsMajor == 2) {
$sHsMajorString = 'Literature';
} elseif ($sHsMajor == 3) {
$sHsMajorString = 'Science';
} elseif ($sHsMajor == 4) {
$sHsMajorString = '(Institute of Technology)';
}
echo "<ul>";
echo "<li>Name: {$sName}</li>";
echo "<li>Phone: {$sPhone}</li>";
echo "<li>Selected Major: {$sMajor}</li>";
echo "<li>High School Major: {$sHsMajorString}</li>";
echo "<li>High School GPA: {$sHsGpa}</li>";
echo "</ul>";
}
?>
答案 2 :(得分:0)
根据您的问题,我认为仅仅为了批准或拒绝而发送用户会话是不明智的。这可能会使您的数据库容易批准或拒绝错误的结果,因为在某些情况下您可能会忘记取消设置会话。
我建议您使用 $ _ POST 或 $ _ GET 。
例如在你的问题中,我会改变
此$id = $_SESSION['id'];
在student_information.php页面中显示为$id = $_GET['id'];
并在链接中更正您的代码,部分代码不正确
例如,在你的代码中,我看到你回应了另一个不推荐的回声,而且你还在另一个语法<?php
中添加了另一个<?php
语法,也不推荐。
即。这一行
echo "<td><button name='stInfo' value='{$sId}'><a href='student_information.php?id=<?php echo ".'"$row[$id]"'."; ?>' target='_blank' style='color: #000000; text-decoration: none;' onClick='pop_up(this)'>Student Details</a></button></td>";
尝试替换此部分
<a href='student_information.php?id=<?php echo ".'"$row[$id]"'."; ?>...
这样的事情
<a href='student_information.php?id=".$sId.".....
在您的student_informtion.php页面中。由于您只显示一个学生,我没有看到尝试显示列表的原因。即这部分
while($row = mysqli_fetch_array($result)) {....
希望这会有所帮助