<?php
//database connection script
require_once('connection.php');
mysql_select_db($database_Connection, $Connection);
//variables needed for paging
$maxPerPage = 6;
$page = empty($_GET['page']) ? 1 : intval (trim ( $_GET['page']));
$offset = ($page - 1) * $maxPerPage;
//set up columns
//note the maxPerPage is still respected
$columns = 1;
$columnWidth = (100 / $columns) - 5;
//pull in data
$sql = "select sql_calc_found_rows * from directors limit $maxPerPage offset $offset";
$result = mysql_query($sql) or die (mysql_error());
//get row count
$countResult = (int) mysql_result(mysql_query("select found_rows()"),0,0);
//calculate number of pages
$numPages = ceil($countResult/$maxPerPage);
$pageLinks = getPageLinks($page, $numPages);
//output sample styles for page links
echo <<<CSS
<style type="text/css">
/* zero default behaviouts */
body,html, div, span, li, ul, ol, h1, h2, h3,
a, table, tbody, thead,tfoot, th, td, tr,
select, textarea, input, img { margin:0; padding:0; text-decoration:none;}
/*basic typography */
body, input, select, th, td{
font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
font-size:67%;
color: black;
}
/* page links styles */
.pageLinks{ width:80%; margin:0 auto; color:#5744ff; overflow-y:hidden; clear:both;}
.firstlast { width:5em;}
.nextprev{ width: 5em;}
.pageLink{ width: 1.5em; float:left; border: 1px solid #040404; text-align: center; margin-right: 0.7em;}
.curPage{ background-color:#7d74a2;}
.pageLink a{ text-decoration:none; color: #5744ff;}
.pageLink a:hover{ background-color:#82fd36;}
.pageLink:hover{ border-color:#f63c45; background-color:#82fd36;}
.pageLink a:visited{ text-decoration:none; color; #5744ff;}
/* page styles */
.pageContents { width:80%; clear:both; overflow-y:hidden;}
.pageContents .columnItem{ float:left; width:{$columnWidth}%}
</style>
CSS;
//output the page links
echo $pageLinks;
//output the page content
echo <<<HTML
<div class="pageContents">
HTML;
while ($row = mysql_fetch_assoc($result)){
echo <<<HTML
<div class="columnItem>
<h4>{$row['Title']} {$row['LastName']}</h4>
<a href="/preview/upload/upload/{$row['File']}">
<img src="/preview/upload/upload/small/{$row['File']}" alt="{$row['FirstName']}"/>
</a>
<p>{$row['summary']}</p>
<p class="price">
Position: <span>Director</span>
</p>
<p>
<a href="product.html" class="add">Career Path</a>
<a href="product.html" class="more">More info</a>
</p>
</div>
HTML;
}
//close page content div
echo "</div>";
//add bottom pageLinks too
echo $pageLinks;
function getPageLinks($page, $numPages){
$links = '';
//plot individual pages
for($i=1; $i<=$numPages; $i++){
$class = ($page == $i) ? 'pageLink curPage' : 'pageLink';
$links .= <<<HTML
<div class="$class"><a href="{$_SERVER['PHP_SELF']}?page=$i}">$i</a></div>
HTML;
}
if ($page == 1){
$first = '';
$previous = '';
} else {
$first = <<<HTML
<div class="firstlast pageLink"><a href="{$_SERVER['PHP_SELF']}?page=1}">First</a></div>
HTML;
$previous = $page - 1;
$previous = <<<HTML
<div class="nextprev pageLink"><a href="{$_SERVER['PHP_SELF']}?page=$previous}">Previous</a></div>
HTML;
}
if ($page == $numPages){
$last = '';
$next = '';
} else {
$last = <<<HTML
<div class="firstLast pageLink"><a href="{$_SERVER['PHP_SELF']}?page=$numPages}">Last</a></div>
HTML;
$next = $page + 1;
$next = <<<HTML
<div class="nextprev pageLink"><a href="{$_SERVER['PHP_SELF']}?page=$next}">Next</a></div>
HTML;
}
return <<<HTML
<div class="pageLinks">{$first}{$previous}{$links}{$next}{$last}</div>
HTML;
}
?>