$selArticles = "
SELECT
`id`,
`title`,
`description`,
`link`
FROM
`articles`
";
$getArticles = mysqli_query($conn, $selArticles);
$num = 1;
echo '<table class="uk-table uk-table-divider uk-table-hover uk-table-justify"><thead>
<tr><th>Номер</th><th>Заголовок</th><th>Описание</th></tr>
</thead><tbody id="result_form">';
while ($arrArticles = mysqli_fetch_array($getArticles)) {
echo '<tr>
<td>' . $num++ . '</td>
<td class="uk-table-shrink uk-text-nowrap">' . $arrArticles[1] . '</td>
<td class="uk-text-truncate uk-table-expand">' . $arrArticles[2] . '</td>
<td class="uk-table-shrink"><a class="uk-button uk-button-secondary" href="../pages/' . $arrArticles[3] . '.php">ОТКРЫТЬ</a></td>
<td class="uk-table-shrink"><a class="uk-button uk-button-primary" href="update-article.php?id=' . $arrArticles[0] . '">ИЗМЕНИТЬ</a></td>
<td class="uk-table-shrink"><a getdata="id=' . $arrArticles[0] . '&link=' . $arrArticles[3] . '&delete=true" class="ajax_form uk-button uk-button-danger">УДАЛИТЬ</a></td>
</tr>';
}
echo '</tbody></table>';
$(document).ready(function() {
$(".ajax_form").click(
function() {
sendAjaxForm('result_form', 'ajax_form', 'create-article.php');
return false;
}
);
});
function sendAjaxForm(result_form, ajax_form, url) {
jQuery.ajax({
url: url, //Адрес страницы
type: "GET", //Метод отправки
dataType: "html", //Формат данных
data: $(".ajax_form").attr('getdata'),
success: function(response) { //Успешно
result = JSON.parse(response);
console.log(result);
document.getElementById(result_form).innerHTML = result;
},
error: function(response) { //Ошибка
document.getElementById(result_form).innerHTML = "Ошибка";
console.log(result);
}
});
}
elseif ($delete == 'true') {
$id = $_GET['id'];
$link = $_GET['link'];
$delArticles = "DELETE FROM articles WHERE ID = '$id'";
mysqli_query($conn, $delArticles);
unlink('../pages/' . $link . '.php');
$selArticles = "
SELECT
`id`,
`title`,
`description`,
`link`
FROM
`articles`
";
$getArticles = mysqli_query($conn, $selArticles);
$num = 1;
while ($arrArticles = mysqli_fetch_array($getArticles)) {
$tor[] = '<tr>
<td>' . $num++ . '</td>
<td class="uk-table-shrink uk-text-nowrap">' . $arrArticles[1] . '</td>
<td class="uk-text-truncate uk-table-expand">' . $arrArticles[2] . '</td>
<td class="uk-table-shrink"><a class="uk-button uk-button-secondary" href="../pages/' . $arrArticles[3] . '.php">ОТКРЫТЬ</a></td>
<td class="uk-table-shrink"><a class="uk-button uk-button-primary" href="update-article.php?id=' . $arrArticles[0] . '">ИЗМЕНИТЬ</a></td>
<td class="uk-table-shrink"><a getdata="id=' . $arrArticles[0] . '&link=' . $arrArticles[3] . '&delete=true" class="ajax_form uk-button uk-button-danger">УДАЛИТЬ</a></td>
</tr>';
}
$tor2 = implode("", $tor);
echo json_encode("$tor2");
}