我想使用$ _GET ['student_id']顯示所有具有相同ID的行,但數據表錯誤,這是我的代碼。一旦我從url得到id例如: example.com/example.php?=2222
所有帶2222的id都會顯示出來。
Fetch.php
<?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);
?>
數據表呼叫 我想顯示使用$ _GET相同的ID [ 'student_id數據'],但數據表的錯誤,這是我的代碼所有的行。一旦我得到的ID從URL例如: example.com/example.php?=2222
<script type="text/javascript" language="javascript" >
$(document).ready(function(){
$('#add_button').click(function(){
$('#user_form')[0].reset();
});
var dataTable = $('#user_data').DataTable({
"processing":true,
"serverSide":true,
"order":[],
"ajax":{
url:"fetch.php",
type:"POST"
},
"columnDefs":[
{
"targets":[0, 3, 4],
"orderable":false,
},
],
});
$(document).on('click', '.delete', function(){
var user_id = $(this).attr("id");
if(confirm("Are you sure you want to delete this?"))
{
$.ajax({
url:"delete.php",
method:"POST",
data:{user_id:user_id},
success:function(data)
{
alert(data);
dataTable.ajax.reload();
}
});
}
else
{
return false;
}
});
});
</script>
這是我所有的在我過去的問題與代碼。 我想使用$ _GET ['student_id']顯示所有具有相同ID的行,但數據表錯誤,這是我的代碼。一旦我得到的ID從URL例如: example.com/example.php?=2222
你沒有'student_id'在您的網址。是錯字嗎?應該是'example.com/example.php?student_id = 2222' –
對不起,它是一個錯字。但讓我們假設它的網址是正確的。但datatables總是顯示一個錯誤 – Aizen
爲什麼不'SELECT * FROM personal WHERE student_id = $ id'你不應該使用像,你需要了解sql注入 – rtfm