-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNews.php
48 lines (41 loc) · 1.5 KB
/
News.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
require_once ("Controller.php");
class News extends Controller
{
public function add($name_ofnew, $name_description, $link_img)
{
$sth = $this->dbh->query('INSERT INTO News (name, description, link) VALUES ("' . $name_ofnew . '", "' . $name_description . '","' . $link_img . '")');
header('Location: /news.html');
}
public function edit($name, $name_description, $link_img)
{
// $sth = $this->dbh->query('UPDATE News SET description="" WHERE name="' . $name_ofnew . '"');
$sth = $this->dbh->query("UPDATE News SET description='$name_description', link='$link_img' WHERE name='$name'");
header('Location: /news.html');
}
public function delete($name_ofnew)
{
// $sth = $this->dbh->query('DELETE FROM News WHERE name="' . $name_ofnew . '"');
// echo 'DELETE FROM News WHERE name_ofnew="' . $name_ofnew . '"';
// header('Location: /news.html');
$this->delete_from_db("News", "name", $name_ofnew);
}
public function show()
{
$sth = $this->dbh->query("SELECT * FROM News;");
$arr=[];
while ($row = $sth->fetch())
{
// echo var_dump($row);
// echo "<hr>";
$arr[] = $row;
}
// echo var_dump($arr);
foreach ($arr as $element)
{
// echo var_dump($element)."<hr>";
echo "<h3>$element[1]</h3> <p>$element[2]</p><img src='$element[3]'><hr/> ";
}
//header('Location: /news.html');
}
}