onigiri
01-05-2006, 04:41 AM
I have a dynamic navigation script in the page of my blog that displays the entries. This script is supposed to make it so there are only five entries displayed per page, and it will make pages based on the number of entries divided by five. The script has no problem creating pages, but it displays all of the entries on every page. (Did I explain the problem clearly enough?) :o
index.php:
<?php
//connect to the database
require_once("config.php");
//Gather the posts from the database
$query = "SELECT id, post, title, create_time FROM blog ORDER BY id DESC";
$query_result = mysql_query($query,$db) or die(mysql_error());
// dynamic navigation variables
$rows_per_page = 5;
$total_records=mysql_num_rows($query_result);
$pages = ceil($total_records / $rows_per_page);
$screen = $_GET["screen"];
if (!isset($screen)) {
$screen=0;
}
$start = $screen * $rows_per_page;
$query .= " LIMIT $start, $rows_per_page";
$result= mysql_query($query) or die
("Could not execute query : $query." . mysql_error());
if(mysql_num_rows($query_result) < 1) {//no posts
echo "Antibaseball has not posted yet.";
} else {
while($row=mysql_fetch_array($query_result)) {
$id = $row['id'];
$entry = $row['post'];
$title = $row['title'];
$create_time = $row['create_time'];
?>
<table width="80%" border="0" cellspacing="1" cellpadding="0" class="entry">
<tr>
<td><p class="header"><?php echo "$entry"; ?></p></td>
</tr>
<tr valign="top">
<td><?php echo "$title"; ?></p></td>
</tr>
<tr>
<td><p class="timestamp"><?php echo "$create_time"; ?></td>
</tr>
<tr>
<td align="right"><?php
if(isset($_SESSION['username'])) {
echo "<a href='admin/admin_editpost.php?id=$id'>Edit Post</a> || <a href='admin/admin_deletepost.php?id=$id'>Delete Post</a>";
}
?>
</td>
</tr>
</table>
<p></p><p></p>
<?
}
}
// Display dynamic navigation here
// create the dynamic links
if ($screen > 0) {
$j = $screen - 1;
$url = "index.php?screen=$j";
echo "<a href=\"$url\">Prev</a>";
}
// page numbering links now
for ($i = 0; $i < $pages; $i++) {
$url = "index.php?screen=" . $i;
$j = $i + 1;
echo " | <a href=\"$url\">$j</a> | ";
}
if ($screen < $pages-1) {
$j = $screen + 1;
$url = "index.php?screen=$j";
echo "<a href=\"$url\">Next</a>";
}
?>
index.php:
<?php
//connect to the database
require_once("config.php");
//Gather the posts from the database
$query = "SELECT id, post, title, create_time FROM blog ORDER BY id DESC";
$query_result = mysql_query($query,$db) or die(mysql_error());
// dynamic navigation variables
$rows_per_page = 5;
$total_records=mysql_num_rows($query_result);
$pages = ceil($total_records / $rows_per_page);
$screen = $_GET["screen"];
if (!isset($screen)) {
$screen=0;
}
$start = $screen * $rows_per_page;
$query .= " LIMIT $start, $rows_per_page";
$result= mysql_query($query) or die
("Could not execute query : $query." . mysql_error());
if(mysql_num_rows($query_result) < 1) {//no posts
echo "Antibaseball has not posted yet.";
} else {
while($row=mysql_fetch_array($query_result)) {
$id = $row['id'];
$entry = $row['post'];
$title = $row['title'];
$create_time = $row['create_time'];
?>
<table width="80%" border="0" cellspacing="1" cellpadding="0" class="entry">
<tr>
<td><p class="header"><?php echo "$entry"; ?></p></td>
</tr>
<tr valign="top">
<td><?php echo "$title"; ?></p></td>
</tr>
<tr>
<td><p class="timestamp"><?php echo "$create_time"; ?></td>
</tr>
<tr>
<td align="right"><?php
if(isset($_SESSION['username'])) {
echo "<a href='admin/admin_editpost.php?id=$id'>Edit Post</a> || <a href='admin/admin_deletepost.php?id=$id'>Delete Post</a>";
}
?>
</td>
</tr>
</table>
<p></p><p></p>
<?
}
}
// Display dynamic navigation here
// create the dynamic links
if ($screen > 0) {
$j = $screen - 1;
$url = "index.php?screen=$j";
echo "<a href=\"$url\">Prev</a>";
}
// page numbering links now
for ($i = 0; $i < $pages; $i++) {
$url = "index.php?screen=" . $i;
$j = $i + 1;
echo " | <a href=\"$url\">$j</a> | ";
}
if ($screen < $pages-1) {
$j = $screen + 1;
$url = "index.php?screen=$j";
echo "<a href=\"$url\">Next</a>";
}
?>