Skip to content

Commit

Permalink
added prev/next paging
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubuntu committed Dec 18, 2010
1 parent 0171a6e commit e295eaa
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,52 @@

?>
<html>
<head><title>Blog</title></head>
<head>
<title>Blog</title>
<style>
.blogpost {
border: 1px black solid;
margin: 5px;
}
.title {
border: 1px black solid;
}
.author {
border: 1px black solid;
}
.tstamp {
border: 1px black solid;
}
.body {
border: 1px black solid;
}
</style>
</head>
<body>

<?php
// grab posts from DB here
if ( !( $db = mysql_connect($dbserver, $dbuser, $dbpword) ) ) die("Error connecting to the database!");

$p = (isset($_GET['p'])) ? $_GET['p'] : 0;
$perpage = 5;
$start = $p*$perpage;

if ( !($r = mysql_db_query("blog", "SELECT * FROM posts ORDER BY tstamp DESC LIMIT $start,$perpage", $db)) ) die("Error getting blog posts!");
while ($post = mysql_fetch_assoc($r) ) {
?>
<div class="blogpost">
<span class="title"><?php echo $post['title'];?></span>
<span class="author"><?php echo $post['author'];?></span>
<span class="tstamp"><?php echo $post['tstamp'];?></span><BR>
<span class="body"><?php echo $post['body'];?></span>
</div>
<?php
}
if ($start != 0 ) {
echo "<a href='?p=".($p-1)."'>prev</a>";
}
echo "<a href='?p=".($p+1)."'>next</a>";
?>
</body>
</html>

0 comments on commit e295eaa

Please sign in to comment.