gpt4 book ai didi

php - 如何添加 $id = $_GET ['student_id' ];并显示所有相同的id

转载 作者:行者123 更新时间:2023-11-29 18:24:09 25 4
gpt4 key购买 nike

我对我的代码非常偏执,因为这是我们的论文。我想使用 $_GET['student_id'] 显示具有相同 id 的所有行,但数据表错误这是我的代码。

<?php
include('db.php');
include('function.php');
$query = '';
$output = array();
$id = $_GET['student_id'];
$query = 'SELECT * FROM personal WHERE student_id LIKE "%'.$_GET["student_id"].'%" ';
$statement = $connection->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
$data = array();
$filtered_rows = $statement->rowCount();
foreach($result as $row)
{
$image = '';
if($row["image"] != '')
{
$image = '<img src="upload/'.$row["image"].'" class="img-thumbnail" width="50" height="35" />';
}
else
{
$image = '';
}
$sub_array = array();
$sub_array[] = $row["student_id"];
$sub_array[] = $row["firstname"]." ".$row['middlename']." ".$row['lastname'];
$sub_array[] = '<a href="edit.php?student_id='.$row["student_id"].'" class="btn btn-info btn-xs update">Personal Info</a>'." ".
'<button type="button" id="'.$row["student_id"].'" class="btn btn-info btn-xs update">Grades</button>'." ".
'<button type="button" id="'.$row["student_id"].'" class="btn btn-info btn-xs update">Payment</button>';
$sub_array[] = '<a href="view.php?student_id='.$row["student_id"].'" class="btn btn-primary btn-xs update">View</a>';
$sub_array[] = '<button type="button" name="delete" id="'.$row["student_id"].'" class="btn btn-danger btn-xs delete">Delete</button>';
$data[] = $sub_array;
}
$output = array(
"draw" => intval($_POST["draw"]),
"recordsTotal" => $filtered_rows,
"recordsFiltered" => get_total_all_records(),
"data" => $data
);
echo json_encode($output);
?>

提前致谢。

最佳答案

假设 student_id 是数字:

$id = intval($_GET['student_id']);
$query = 'SELECT * FROM personal WHERE student_id = '.$id;

足够安全。

此外,这看起来像是 AJAX 调用。让我们看看您的 Javascript 调用和 HTML,看看是否直接从您的 AJAX 调用中调用数据表

关于php - 如何添加 $id = $_GET ['student_id' ];并显示所有相同的id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46328875/

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