gpt4 book ai didi

php 在弹出窗口中显示特定数据

转载 作者:行者123 更新时间:2023-11-29 03:26:15 25 4
gpt4 key购买 nike

我已经创建了一个在线注册系统。我制作了一个无序列表来显示等待批准或拒绝的新待定申请人。我还为每个新申请人添加了一个按钮,以显示他们在待处理表中的数据。

问题是当我添加多个申请人时,它只显示所有申请人的最后一位申请人的详细信息。我已经经历了几个小时,但几天都没有任何效果。

这是我在具有无序列表的页面中的代码:

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>";


}
?>

最佳答案

在您指向 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>";


}
?>

关于php 在弹出窗口中显示特定数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35946930/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com