Skip to content

Commit c9fd9ed

Browse files
added
2 parents 5633ca7 + 4fec8af commit c9fd9ed

File tree

7 files changed

+86
-0
lines changed

7 files changed

+86
-0
lines changed

add.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1+
<<<<<<< HEAD
12
the added text master
3+
=======
4+
this is added text using ab account
5+
>>>>>>> 4fec8af02c9ff5d9fefb5c4f23c69b29d796e539

index.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<<<<<<< HEAD
12
// index.php
23
// load and initialize any global libraries
34

@@ -17,3 +18,31 @@
1718
header('HTTP/1.1 404 Not Found');
1819
echo '<html><body><h1>Page Not Found</h1></body></html>';
1920
}
21+
=======
22+
<?php
23+
// index.php
24+
$link = new PDO("mysql:host=localhost;dbname=blog_db", 'myuser', 'mypassword');
25+
$result = $link->query('SELECT id, title FROM post');
26+
?>
27+
<!DOCTYPE html>
28+
<html>
29+
<head>
30+
<title>List of Posts</title>
31+
</head>
32+
<body>
33+
<h1>List of Posts</h1>
34+
<ul>
35+
<?php while ($row = $result->fetch(PDO::FETCH_ASSOC)): ?>
36+
<li>
37+
<a href="/show.php?id=<?= $row['id'] ?>">
38+
<?= $row['title'] ?>
39+
</a>
40+
</li>
41+
<?php endwhile ?>
42+
</ul>
43+
</body>
44+
</html>
45+
<?php
46+
$link = null;
47+
?>
48+
>>>>>>> 4fec8af02c9ff5d9fefb5c4f23c69b29d796e539

model.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<<<<<<< HEAD
12
/ model.php
23
function open_database_connection()
34
{
@@ -20,4 +21,17 @@ function get_all_posts()
2021
}
2122
close_database_connection($link);
2223
return $posts;
24+
=======
25+
// model.php
26+
function get_post_by_id($id)
27+
{
28+
$link = open_database_connection();
29+
$query = 'SELECT created_at, title, body FROM post WHERE id=:id';
30+
$statement = $link->prepare($query);
31+
$statement->bindValue(':id', $id, PDO::PARAM_INT);
32+
$statement->execute();
33+
$row = $statement->fetch(PDO::FETCH_ASSOC);
34+
close_database_connection($link);
35+
return $row;
36+
>>>>>>> 4fec8af02c9ff5d9fefb5c4f23c69b29d796e539
2337
}

show.php

Whitespace-only changes.

templates/layout.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!-- templates/layout.php -->
2+
<!DOCTYPE html>
3+
<html>
4+
<head>
5+
<title><?= $title ?></title>
6+
</head>
7+
<body>
8+
<?= $content ?>
9+
</body>
10+
</html>

templates/list.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<<<<<<< HEAD
12
!-- templates/list.php -->
23
<!DOCTYPE html>
34
<html>
@@ -18,3 +19,20 @@
1819
</ul>
1920
</body>
2021
</html>
22+
=======
23+
<!-- templates/list.php -->
24+
<?php $title = 'List of Posts' ?>
25+
<?php ob_start() ?>
26+
<h1>List of Posts</h1>
27+
<ul>
28+
<?php foreach ($posts as $post): ?>
29+
<li>
30+
<a href="/show.php?id=<?= $post['id'] ?>">
31+
<?= $post['title'] ?>
32+
</a>
33+
</li>
34+
<?php endforeach ?>
35+
</ul>
36+
<?php $content = ob_get_clean() ?>
37+
<?php include 'layout.php' ?>
38+
>>>>>>> 4fec8af02c9ff5d9fefb5c4f23c69b29d796e539

templates/show.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!-- templates/show.php -->
2+
<?php $title = $post['title'] ?>
3+
4+
<?php ob_start() ?>
5+
<h1><?= $post['title'] ?></h1>
6+
<div class="date"><?= $post['created_at'] ?></div>
7+
<div class="body">
8+
<?= $post['body'] ?>
9+
</div>
10+
<?php $content = ob_get_clean() ?>
11+
<?php include 'layout.php' ?>

0 commit comments

Comments
 (0)