-
Notifications
You must be signed in to change notification settings - Fork 0
/
post_index.php
58 lines (54 loc) · 1.16 KB
/
post_index.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
49
50
51
52
53
54
55
56
57
58
<?php
//this script will display all the current posts in the database
$posts = all_posts();
//shut up warnings
error_reporting(0);
include "includes/header.inc";
?>
<div id="content">
<ul id="subnav">
<li><a href="post_new.php">New Post</a></li>
</ul>
<?php
//build a table of all the posts
postsTable($posts)
?>
</div>
<?php
include "includes/footer.inc";
?>
<?
//this function finds all the posts in the database
function all_posts(){
include "includes/db_con.inc";
$conn = conDB();
$query = "SELECT * FROM posts";
$posts = q($query);
return $posts;
}
//this function
function postsTable($posts){?>
<div id="posts">
<table>
<thead>
<tr>
<th>Title</th>
<th>Content Preview</th>
</tr>
</thead>
<tbody>
<?
while ($post = mysql_fetch_array($posts, MYSQL_ASSOC)){
postRow($post);
}?>
</tbody>
</table>
</div>
<?}
function postRow($post){?>
<tr>
<td><?= $post['title']?></td>
<td><?= substr($post['body'],0, 32)?>...<a href="post_show.php?id=<?=$post['id']?>">[more]</a></td>
</tr>
<?}
?>