Answer the question
In order to leave comments, you need to log in
Returns NULL after loading from the database, why?
Good day. There is a page for deleting from the database, I display 100 records as soon as I scroll to the last records, it starts loading the next 100 so that it does not buggy, since there are 90k records. I use "checkbox" to delete, what is the actual problem, if we select the first 2 records, and press the delete button, delete, but if you select the first 2 records from the next 100 loaded, then it returns NULL when deleting, why? And how can you fix it?
first 100 entries
if (isset($_POST['delete_data'])) {
$cheked = $_POST['check'];
foreach ($cheked as $del_id) {
$del = mysqli_query($connect, "DELETE FROM `test_excel` WHERE `id` = $del_id");
}
}
$result = mysqli_query($connect, "SELECT * FROM `test_excel` LIMIT 100");
while ($row = mysqli_fetch_array($result)) {
echo "<tr><td><input type='checkbox' name='check[]' value='".$row['id']."'></td><td>".$row['id']."</td><td>".$row['name']."</td><td>".$row['nameScore']."</td><td>".$row['organization']."</td></tr>";
}
$(document).ready(function(){
var inProgress = false;
var startFrom = 100;
$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() >= $(document).height() - 100 && !inProgress) {
$.ajax({
url: 'delete_data_ajax.php',
method: 'POST',
data: {
"startFrom" : startFrom
},
beforeSend: function() {
inProgress = true;
}}).done(function(data){
data = jQuery.parseJSON(data);
if (data.length > 0) {
$.each(data, function(index, data){
$(".table_delete").append("<tr><td><input type='checkbox' name='check[]' value='"+ data.id +"'></td><td>"+ data.id +"</td> <td>"+ data.name + "</td> <td>" + data.nameScore + "</td> <td>" + data.organization + "</td></tr>");
});
inProgress = false;
startFrom += 100;
}});
}
});
});
$startFrom = $_POST['startFrom'];
$res = mysqli_query($connect, "SELECT * FROM `test_excel` LIMIT {$startFrom}, 100") or die('нет подключение к бд');
$resSeacrh = array();
while ($row = mysqli_fetch_assoc($res)) {
$resSeacrh[] = $row;
}
echo json_encode($resSeacrh);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question