In general, I made a paginal output that worked successfully with all the sampling conditions (you can select a filter in the form, sort, date, and output everything as needed), but when I decided to do everything through ajax, I had difficulty with that Data occurs only after pressing the button, then the whole selection appears (10 records per page) and the page-by-page navigation along with the selection. On ajax, the sample is displayed using json and everything works, but how to display the function that displays page-by-page navigation I won’t attach my mind. Here is the js code:
$("#sortfilt").submit(function(e) { event.preventDefault(); var showusers = 'showusers'; var sort = $('#sort').val(); var filtgroup = $('#filtgroup').val(); var datefrom = $('#datefrom').val(); var dateto = $('#dateto').val(); $.get("ajax.php", {showusers: showusers, sort: sort, filtgroup: filtgroup, datefrom: datefrom, dateto: dateto}, function (data) { alert(data); data = JSON.parse(data); alert(data); $('#users').empty(); for(var key in data) { var obj = (key, data[key]); $('#users').append("<ul><li><img src=" + obj.imageExtention + "></li><li>" + obj.login + "</li> <li>" + obj.name + "</li> <li>" + obj.email + "</li> <li>" + obj.expirationDateAndTime + "</li> <li><button name='delete' value='" + obj.consumerId + "'>Удалить</button></li></ul>"); } }); }); and here is ajax.php:
if(isset($_GET['showusers'])) { $data = array(); if($_GET['sort']) { $sort = $db->escape($_GET['sort']); $order = " ORDER BY $sort ASC";//формируем запрос } if($_GET['filtgroup'] === 'all') { $filter = ""; } else { $filt = $db->escape($_GET['filtgroup']); $filter = "AND consumer.groupId = '$filt'";//формируем запрос } if($_GET['datefrom'] && $_GET['dateto']) { $from = $db->escape($_GET['datefrom']); $to = $db->escape($_GET['dateto']); $datequery = "AND consumer.expirationDateAndTime BETWEEN '$from' AND '$to'";//добавляем продолжнение запроса на дату, если она введена } else { $datequery = ""; } // Подготовка к постраничному выводу $perpage = 10; // Количество отображаемых данных из БД if (empty(@$_GET['page']) || ($_GET['page'] <= 0)) { $page = 1; } else { $page = (int) $_GET['page']; // Считывание текущей страницы } // Общее количество информации $count = mysqli_num_rows($db->query('SELECT * FROM `consumer`')) or die('error! Записей не найдено!'); $pages_count = ceil($count / $perpage); // Количество страниц // Если номер страницы оказался больше количества страниц if ($page > $pages_count) { $page = $pages_count; } $start_pos = ($page - 1) * $perpage; // Начальная позиция, для запроса к БД //$boom = Reg::linkbar($page, $pages_count); function linkbar($page, $pages_count) { for ($j = 1; $j <= $pages_count; $j++) { // Вывод ссылки if ($j == $page) { echo ' <a style="color: #808000;" >'.$j.'</a> '; } else { echo ' <a style="color: #808000;" href='.$_SERVER['php_self'].'?page='.$j.'&showusers>'.$j.'</a> ';//возможно после showusers нужно добавить ='.$j.' } // Выводим разделитель после ссылки, кроме последней // например, вставить "|" между ссылками if ($j != $pages_count) { echo ' | '; } } return true; } //Выводим запрос $res = $db->query("SELECT * FROM `consumer`, `group` WHERE consumer.groupId = group.groupId $filter $datequery $order LIMIT ".$start_pos.", ".$perpage);//$filter $datequery $order //var_dump($res); while(($row = $db->fetch_assoc($res)) != false) { $data[] = $row; } echo json_encode($data); } Also in this file is the linkbar () function, which displays the navigation and I do not understand how to grasp this function, that the navigation was output along with the selection
epassed to the function, and the second is theevent. Is this what the event exists somewhere higher? - Mr. Brightside