Forum Moderators: coopster
Here's what I got.
$total = total database results;
$limit = 10;
isset($_GET['page'])? $page = $_GET['page'] : $page = 1;
$numPages = ceil($total / $limit);
$offset = ($page - 1) * $limit;
$output = array_slice($database_rslts, $offset, $limit);
$value = $offset+10;
$value2 = $total-$offset;
$numbering = ceil($total / $numPages);
$numtotal = $numbering+$offset;
for($i = 1; $i <= $numPages; $i++){
if($total < $limit){}
else{
($i==1)? print "" : print " , ";
if($i == $page){echo $i;}
else{echo "<a href=\"euroauth.php?page=$i\">$i</a>";}
}
}
Any hints? Thanks
fintan.
////////////////CODE/////////////////////////////
<?php
// Set some variables for script
// To show each page by number set to Y. Set to N for prev-next links only
$showpages = "N";
// Set number of records to be displayed per page $limit=somenumber
$limit=5;
if (empty($offset))
{
$offset=0;
}
$query = 'select * from Gallery';
$result = mysql_query($query);
$numrows = mysql_num_rows($result);
if ($numrows>0)
{
$query2 = 'select * from Gallery '
."limit $offset,$limit";
$result2 = mysql_query($query2);
$numrows2 = mysql_num_rows($result2);
echo ("<h1>Image Gallery</h1>\n");
echo ("<br />\n");
echo ("<div id='gallery'>\n");
echo "<a href='Gallery.htm'>Go Back</a><p>";
while ($row=mysql_fetch_assoc($result2)){
$id = $row['image_id'];
$large = $row['large'];
$small = $row['small'];
$description = $row['description'];
echo " ";
echo " ";
echo "<table width='50%' border='3' bordercolor='#3300FF'>";
echo "<tr>";
echo "<td width='15%'>";
echo '<a href="';
echo $url;
echo $large;
echo '"';
echo ' target=top>';
echo '<img src="';
echo $url;
echo $small;
echo '"';
echo 'alt="';
echo $description;
echo '"';
echo '>';
echo "</a>";
echo "</td>";
echo " ";
echo "<td>";
echo $description;
echo " ";
echo "</td>";
echo "</tr>";
echo "</table>";
};
//determine number of pages needed
$pages=intval($numrows/$limit);
//if number of records isn't evenly divisible by the number of pages above, add another page.
if ($numrows%$limit)
{
$pages++;
}
//set value of first record to be displayed
$first_record = $offset + 1;
echo "<br />";
//see if we're on the last page
if (!((($offset)/$limit)+1==$pages))
{
$last_record = $offset + $limit;
//is last page
echo " <strong>$last_record</strong> of <strong>$numrows</strong> image(s). Click on image to enlarge<br />";
}
else
{
//is NOT last page - send this to browser
echo " <strong>$numrows</strong> of <strong>$numrows</strong> image(s). Click on image to enlarge<br>";
}
echo "<br />\n";
//prepare and display links to other results in browser
if ($offset!= 0)
{
$prevoffset=$offset-$limit;
//create a previous link - if we're not on the first page
echo "<a class='nav' href='$PHP_SELF?offset=$prevoffset'><< Prev</a> \n";
}
//construct that shows just prev-next or all page numbers
if ($showpages == Y)
{
if ( $pages!= 1 )
{
for ($i=1;$i<=$pages;$i++)
{
$newoffset=$limit*($i-1);
if ( ((($offset)/$limit)==($i-1)) )
{
echo "$i \n";
}
else
{
echo "<a class='nav' href='$PHP_SELF?offset=$newoffset'>$i</a> \n";
}
}
}
}
if (!((($offset)/$limit)+1==$pages) && $pages!=1)
{
$newoffset=$offset+$limit;
//create a next link - if we're not on the last page
echo ("<a class='nav' href='$PHP_SELF?offset=$newoffset'>Next >></a><p>\n");
}
}
else
{echo "No more records to display!";
}
echo ("</div>\n");
}
?>
example:
alnalwnlawlanlwnxal;xna;wxnklnklnklwanxkawnxla
laknxlkawnlawnlxknwlknxlaknwklaxnakxkalxnklnxla
lanlxkanxlanwlkanlkxnalknlaknakxnwalnlanxalknxl
10 of 32 Reviews(s).
1 2 3 Next Page >>
if u goto next page u get:
alnalwnlawlanlwnxal;xna;wxnklnklnklwanxkawnxla
laknxlkawnlawnlxknwlknxlaknwklaxnakxkalxnklnxla
lanlxkanxlanwlkanlkxnalknlaknakxnwalnlanxalknxl
20 of 32 Reviews(s).
<< Previous Page 1 2 3 Next Page >>
Etc....
thats they way it works