<?
$news=mysqli_query($connect,"SELECT * from `news` ORDER BY `data`");
$news_res=mysqli_fetch_array($news);
do{
$title=$news_res['title_n'];
$text=$news_res['text_n'];
$id_new=$news_res[0];
echo'
<div class="container border border-info rounded qwe" style="margin-top:3%">
<div class="row justify-content-center">
<div class="col-md-auto">
<p class="text_cours" style="margin-top:9%;font-size:1.3vw; font-weight:bold;text-transform:uppercase">'.$news_res['title_n'].'</p>
</div>
</div>
<div class="row justify-content-center">
<div class="col" style="max-width:60%">
<p class="text_cours" style="margin-top:3%;font-size:1.2vw">'.$news_res['text_n'].'</p>
</div>
<div class="col" style="max-width:35%">
<img style=" max-width:100%; margin-left:2%;margin-top:3%; border: 0.3em solid rgb(0,197,183);" src="images/'.$news_res['image_n'].'"/>
</div>
</div>
<div class="row justify-content-left">
<div class="col-md-auto">
<p class="text_cours" style="margin-left:28%;font-size:1vw; font-weight:bold">'.date('d.m.Y', strtotime($news_res['data'])).'</p>
</div>
</div>
<div class="row justify-content-center" style="margin:1% auto" >
<div class="col-md-auto">
<button class="text_cours btn btn-info change_new" id="change_new" value="'.$id_new.'" style="font-size:small;">ИЗМЕНИТЬ</button>
</div>
<div class="col-md-auto">
<button class="text_cours btn btn-info" id="del_new" value="'.$id_new.'" style="font-size:small;">УДАЛИТЬ</button>
</div>
</div>
<div class="form_ch_new row justify-content-center " id="form_ch_new[]" style="display:none">
<form>
<div class="border border-info rounded" style="margin:2% 10%" id="change_new_area">
<div class="form-group row justify-content-center">
<p class="text_cours" style="font-size:1.1vw; font-weight:bold">Изменить новость</p>
</div>
<div class="form-group row justify-content-center ">
<label class="col-sm-5 col-form-label" for="new_title">Новое название:</label>
<div class="col-sm-6">
<input type="text" class="form-control form-control-sm" value="'.$title.'" name="new_title" id="new_title"/>
<small class="form-text text-muted">Можно не менять название, просто оставьте это поле без изменений.</small>
</div>
</div>
<div class="form-group row justify-content-center ">
<label class="col-sm-5 col-form-label" for="new_text">Новый текст новости:</label>
<div class="col-sm-6">
<textarea class="form-control new_text" name="new_text" id="new_text" rows="5"/>'.$text.'</textarea>
<small class="form-text text-muted">Можно не менять текст, просто оставьте это поле без изменений.</small>
</div>
</div>
<div class="form-group row justify-content-center ">
<label class="col-sm-5 col-form-label" for="new_image">Новое изображение:</label>
<div class="col-sm-6">
<input type="file" class="form-control-file" style="font-size:small" name="new_image" id="new_image"/>
<small class="form-text text-muted">Можно не загружать новое изображение.</small>
</div>
</div>
<input type="hidden" value="'.$id_new.'" class="go_change" name="go_change">
<div class="form-group row justify-content-center ">
<button class="btn btn-info go_change_new" style="font-size:small" name="'.$id_new.'" value="'.$id_new.'">OK</button>
</div>
</div>
</form>
</div>
</div>
';
}while($news_res=mysqli_fetch_array($news));
?>
$('.go_change_new').bind('click', function (e) {
e.preventDefault();
let id_new = $(this).attr("name");
let new_title = $('input[name="new_title"]').val(),
new_text = $('.new_text').val();
let formData = new FormData();
formData.append('new_title', new_title);
formData.append('new_text', new_text);
formData.append('id_new', id_new);
formData.append('new_image', new_image);
$.ajax({
url: '/change_new_res.php',
type: 'POST',
dataType: 'json',
processData: false,
contentType: false,
cache: false,
data: formData,
success(data) {
if (data.status) {
alert(data.message);
window.location.replace('admin.php');
} else {
alert(data.message);
}
}
});
});