As my first post, I want to say it's great to be a part of this community.
I am currently just needing some help in creating a pagination effect based off this. I've been talking to some people about this idea, as my original approach was using a mysql database, but after looking at the site, they suggested trying a "front controller pattern", maping to a directory in the filesystem and the page as a document within that filesystem eg:
Code: Select all
wwwroot/
|
|
---stories/
|
|
---elaine/
| |
| |
| ---1.html
| 2.html
| 3.html
|
|
---tremain/
|
|
---1.html
2.html
...
Code: Select all
// page design code here
<div id="story">
<?php
include("stories/$_GET['story']/$_GET['page']");
// Pagination code goes here
?>
Code: Select all
// database connection info
$conn = mysql_connect('localhost','dbusername','dbpass') or trigger_error("SQL", E_USER_ERROR);
$db = mysql_select_db('dbname',$conn) or trigger_error("SQL", E_USER_ERROR);
// find out how many rows are in the table
$sql = "SELECT COUNT(*) FROM numbers";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
$r = mysql_fetch_row($result);
$numrows = $r[0];
The next part of this code makes abit more sense to me as once I get the total pages of a specified directory, things like $currentpage will fall into place.
Code: Select all
// get the current page or set a default
if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
// cast var as int
$currentpage = (int) $_GET['currentpage'];
} else {
// default page num
$currentpage = 1;
} // end if
// if current page is greater than total pages...
if ($currentpage > $totalpages) {
// set current page to last page
$currentpage = $totalpages;
} // end if
// if current page is less than first page...
if ($currentpage < 1) {
// set current page to first page
$currentpage = 1;
} // end if
Code: Select all
// if not on page 1, don't show back links
if ($currentpage > 1) {
// show << link to go back to page 1
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> ";
// get previous page num
$prevpage = $currentpage - 1;
// show < link to go back to 1 page
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> ";
} // end if
Thanks all for your time.