<?php
// include the connection, truncate and bbcode functions
require_once("path_to_connection");
require_once("path_to_truncate");
require_once("path_to_BBCODE");
// set up the connection
$conn = connection_access();
// use the first query to get the count from the posts table
$query = "SELECT COUNT(*) FROM posts";
if ($result = $conn->query($query))
{
$row = $result->fetch_row();
// assign the total to a variable
$total_entries = $row[0];
}
// close the first result and set the number of page entries
$result->close();
$entries_per_page = 3;
if (isset($_GET['page_number']))
{
// assign the page number to a variable
$page_number = $_GET['page_number'];
}
else
{
// give it 1
$page_number = 1;
}
// divide and round total_entries with entries_per_page
$total_pages = ceil($total_entries / $entries_per_page);
// tell the database where to start fetching by setting an offset
$offset = ($page_number - 1) * $entries_per_page;
// get the entries out and display them
$query1 = "SELECT post_id, author_id, author_name, DATE_FORMAT(date_posted, '%W, %M %d, %Y %l:%i %p') AS formatted_date, author_email, a.category_id, c.category_name, title, post_body FROM posts a INNER JOIN categories c ON a.category_id = c.category_id ORDER BY date_posted DESC LIMIT " . $offset . ", " . $entries_per_page;
if ($result1 = $conn->query($query1))
{
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Rebirth Test Page</title>
<meta name="keywords" content="harry potter,hogwarts,hogwarts rpg,hogwarts online,jk rowling">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta http-equiv="cache-control" content="no-cache">
<link href="/css/general2.css" rel="stylesheet" type="text/css">
<link href="/css/ulists.css" rel="stylesheet" type="text/css">
<link href="/css/ticker.css" rel="stylesheet" type="text/css">
<script language="javascript" type="text/javascript" src="/javascripts/scroll.js"></script>
</head>
<body>
<div id="wrapper">
<div id="headers">
<div id="header1"></div>
<div id="header2">
</div>
</div>
<div id="navigation">
<!-- Begin Navigation Menu -->
<?php // include the navigation menu
include("../includes/navigation3.html"); ?>
<!-- End Navigation Menu -->
</div>
<div id="right">
<div id="newsBody">
<div id="newsHead">
<img src="/images/misc/latest_news.gif" border="0" width="200" height="60" alt="Latest News" title="Latest News">
</div>
<div id="newsWindow">
<div align="center" id="newsText" onMouseOver="window.clearTimeout(scrollTimer);" onMouseOut="scroll();"><p>Hello world!</p></div>
</div>
</div>
</div>
<div align="center" id="center">
<div id="welcome">
<p>Welcome to Ultimate Hogwarts: The Rebirth! Ultimate Hogwarts is an online Hogwarts Role Playing Game where fans
of the Harry Potter books can create their own character, attend Hogwarts, visit the Ministry of Magic, or just
interact with other characters in our story! If you would like to know more about this site, please visit the Rules
page and FAQ page. Once you're ready to enroll, you can go to the Character Applications forum at our message board
and begin getting your character approved.</p>
</div>
<div id="news">
<?php
// DISPLAYING ENTRIES NOW
while ($obj = $result1->fetch_object())
{
echo "<div class='news'><a href='show_news.php/" . $obj->post_id . "/" . $obj->title . "'>" . strip_tags($obj->title, '<p><br><a><b><i>') . "</a></div>";
echo "<div class='news'><b>Posted by:</b> " . strip_tags($obj->author_name, '<p><br><a><b><i>') . " on " . $obj->formatted_date . " in " . strip_tags($obj->category_name, '<p><br><a><b><i>') . "</div>";
echo "<div class='news_post'>" . BBCODE(truncate(strip_tags($obj->post_body, '<p><br><a><b><i>'))) . "</div>"; }
echo "<br><br>";
// now, display the pages
for ($counter = 1; $counter <= $total_pages; $counter++)
{
if ($counter == $page_number)
{
echo $counter;
}
else
{
echo "<a href='test_copy.php?page_number=$counter'>$counter</a>";
}
}
$result1->close(); } else { printf("Result Error %s\n", $conn->error); } $conn->close();
?>
</div>
</div>
</div>
</div>
</body>
</html>
I finally got around to getting my news script paginated. However, I want to limit the number of pages shown on each page. What edits should I make?