<?php if(isset($arr)):?>
<?php foreach ($arr as $item):?>
<p><?= $item['id_article']; ?></p>
<h1><?= $item['title']; ?></h1>
<p><?= $item['content']; ?></p>
<a href="?delete=<?= $item['id_article'] ?>">Удалить</a>
<a href="update.php?id=<?= $item['id_article'] ?>">Изменить</a>
<?php endforeach;?>
<?php
include_once ('conf/db.php');
echo 'update.php?id=' . $_GET['id'];
/**
* ------------------------------------
* Обновление статей в базу данных
* ------------------------------------
*/
if(isset($_GET['id']))
{
$id = (int)$_GET['id'];
$select = mysqli_query(connect_db(),"SELECT * FROM `articles` WHERE `id_article` = '$id' ");
if(!$select)
die(mysqli_error());
$n = mysqli_num_rows($select);
$arr = array();
for ($i = 0; $i < $n; $i++)
{
$row = mysqli_fetch_assoc($select);
$arr[] = $row;
}
echo '<pre>';
var_dump($arr);
echo '</pre>';
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<a href="index.php">Вернуться назад</a>
<form>
<textarea></textarea><br>
<textarea></textarea><br>
<input name="update" type="submit" value="Изменить" />
</form>
</body>
</html>
if (isset($_GET['update']))
{
$id = $_GET['update'];
$title = $arr['title'];
$content = $arr['content'];
$update_query = "UPDATE `articles` SET `id` = '{$id}' WHERE `id` = '{$id}', `title` = '{$title}', `content` = '{$content}'";
echo '<pre>';
var_dump($update_query);
echo '</pre>';
if(mysqli_query(connect_db(), $update_query))
{
if(!$update_query)
{
die(mysqli_error());
}
else
{
header("Location: update.php");
}
}
}
$select = mysqli_query(connect_db(),"SELECT * FROM `articles` ORDER BY `id_article` DESC ");
if(!$select)
die(mysqli_error());
$n = mysqli_num_rows($select);
$arr = array();
for ($i = 0; $i < $n; $i++)
{
$row = mysqli_fetch_assoc($select);
$arr[] = $row;
}