I have been working on this code for sumtime now...i am trying to display a total of 6 pics per page.....divided in 3 rows.....and create pages for the next pics in the directory.....like this
Page[1] 2 3 4
image1 image2
image3 image4
image5 image6
but i am not geting the idea of how to exactly display the images in the rite way and how to create this pagination as i desire.....been working on it for long time now....and i ma not tht gud in php....any help wud be greatly appreciated and i have atttached my code also so tht anyone can copy and work on it and help me....thx in advance(i am not using any database)
<?php
$dir="./images/g8_thumbs";
if (is_dir($dir)) {
$fd = @opendir($dir);
if($fd) {
while (($part = @readdir($fd)) == true) {
if ($part != "." && $part != "..") {
$break=explode(".", $part);
if(($break[1] == "gif") OR ($break[1] == "jpg") OR ($break[1] == "png"))
{
$file_array[]=$part;
}
}
}
}
sort($file_array);
reset($file_array);
}
// declare data file and lines per page
$lines=2;
// grab start position
if(isset($GET['next']) && is_numeric($GET['next']))
{
$start=$GET['next'];
}
elseif(isset($GET['pre']) && is_numeric($GET['pre']))
{
$start=$GET['pre'];
}else{
$start=0;
}
$hold=$start;
//total lines
$count=count($file_array);
if($start>$count-$lines)
{
$start=$count-$lines;
}
if($start<0) { $start=0; }
$limit=$start+$lines;
// loop through array and display
//display next previous
if($start>0)
{
$pre=$hold-$lines;
echo"<a href=\"".$PHP_SELF."?pre=".$pre."\" >Previous</a> ";
}
if(($start<$count)-$lines)
{
$nex=$hold+$lines;
if($nex==$count)
{
echo"";
}
else
{
echo"<a href=\"".$PHP_SELF."?next=".$nex."\" >Next</a> ";
}
}
// We want three columns:
$display_columns = 3;
// We have enough to figure out how many empty spaces there'll be left at
// the bottom of the table.
$padding = ($display_columns-1)-(($count-1)%$display_columns);
//
// We also know enough to know how many rows there'll be, but I for one
// don't really care about that right now.
echo "<table>";
// Let's begin our loop.
for($i=$start; $i<$limit; $i++)
{
$name=explode('.',$file_array[$i]);
$imgname=$name[0];
// Whenever $i is a multiple of $display_columns (including 0),
// it's a sign that we're hitting the start of a new row.
if($i%$display_columns == 0)
echo "<tr>";
//Now for an item.
echo "<td>";
echo "<a href=\"./images/g8/$file_array[$i]\" target='_blank'><img src=\"$dir/$file_array[$i]\" width=100 height=100 alt=\"$imgname\"></a>";
echo "</td>";
//Whenever $i is one less than a multiple of $display_columns,
// it's a sign that we're hitting the end of the current row.
if(($i%$display_columns) == $display_columns-1)
echo "</tr>";
}
// That's all the items done; now we just need to pad the table out and
// wrap up. We don't need to pad at all if $padding is zero.
if($padding!=0)
{ for($i=0;$i<$padding;$i++)
echo "<td></td>";
echo "</tr>";
}
echo "</table>";
?>