probably more a newbie question but:
I have a pagination set up to display images uploaded to my site. I wanted 1 result per page.
So far, i can get it to display the 1st result from the database query, and display the total number of pages.
However, when you click the 'next' arrow or a page number, my site says the page cannot be found. I'm stumped here and pretty much a complete novice so any help is appreciated!
working demo of problem(not styled!): http://www.creative-spotlight.com/dynamic-site/start-page/display2.php
code, 'display.php':
<?php
$rpp = 1; // results per page
$adjacents = 1;
$page = intval($_GET["page"]);
if($page<=0) $page = 1;
$reload = $_SERVER['PHP_SELF'];
// connect to your DB:
$link_id = mysql_connect('SENSORED STUFF') or die(mysql_error());
$db = mysql_select_db('rpsep2',$link_id) or die(mysql_error());
// select appropriate results from DB:
$sql ="SELECT filepath FROM uploads ORDER BY date DESC";
$result = mysql_query($sql);
// count total number of appropriate listings:
$tcount = mysql_num_rows($result);
// count number of pages:
$tpages = ($tcount) ? ceil($tcount/$rpp) : 1; // total pages, last page number
$count = 0;
$i = ($page-1)*$rpp;
while(($count<$rpp) && ($i<$tcount)) {
mysql_data_seek($result,$i);
$query = mysql_fetch_array($result);
// output each row:
?>
<div id="mainWindow">
<div id="image"><img src="<? echo $query['filepath']?>" class="image"/></div></div>
<?
$i++;
$count++;
}
include("pagination2.php");
echo paginate_two($reload, $page, $tpages, $adjacents);
?>
and pagination2.php
<?php
/*************************************************************************
php easy :: pagination scripts set - Version Two
==========================================================================
Author: php easy code, www.phpeasycode.com
Web Site: http://www.phpeasycode.com
Contact: webmaster@phpeasycode.com
*************************************************************************/
function paginate_two($reload, $page, $tpages, $adjacents) {
$firstlabel = "« ";
$prevlabel = "‹ ";
$nextlabel = " ›";
$lastlabel = " »";
$out = "<div class=\"pagin\">\n";
// first
if($page>($adjacents+1)) {
$out.= "<a href=\"" . $reload . "\">" . $firstlabel . "</a>\n";
}
else {
$out.= "<span>" . $firstlabel . "</span>\n";
}
// previous
if($page==1) {
$out.= "<span>" . $prevlabel . "</span>\n";
}
elseif($page==2) {
$out.= "<a href=\"" . $reload . "\">" . $prevlabel . "</a>\n";
}
else {
$out.= "<a href=\"" . $reload . "&page=" . ($page-1) . "\">" . $prevlabel . "</a>\n";
}
// 1 2 3 4 etc
$pmin = ($page>$adjacents) ? ($page-$adjacents) : 1;
$pmax = ($page<($tpages-$adjacents)) ? ($page+$adjacents) : $tpages;
for($i=$pmin; $i<=$pmax; $i++) {
if($i==$page) {
$out.= "<span class=\"current\">" . $i . "</span>\n";
}
elseif($i==1) {
$out.= "<a href=\"" . $reload . "\">" . $i . "</a>\n";
}
else {
$out.= "<a href=\"" . $reload . "&page=" . $i . "\">" . $i . "</a>\n";
}
}
// next
if($page<$tpages) {
$out.= "<a href=\"" . $reload . "&page=" .($page+1) . "\">" . $nextlabel . "</a>\n";
}
else {
$out.= "<span>" . $nextlabel . "</span>\n";
}
// last
if($page<($tpages-$adjacents)) {
$out.= "<a href=\"" . $reload . "&page=" . $tpages . "\">" . $lastlabel . "</a>\n";
}
else {
$out.= "<span>" . $lastlabel . "</span>\n";
}
$out.= "</div>";
return $out;
}
?>
p.s have been to the site where the code is from and there is no help on there 🙁