/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Paginate a result

Good day to you,
I need to paginate the result of this code :

[code=php]

<?php
$image_counter = -1;
$row_counter = 0;
$cell_counter = 0;
$show=array(‘.jpg’,’.JPG’,’.gif’,’.GIF’);

$val= $_GET[‘folder’];
$val1 = $_GET[‘folder’];
$val0 = $val1;
$val.=”/”;

$path = “$val”;
$path2 = str_replace(“Pic-S”, “Pic-B”, $val);
$dirshort = substr($val,20);
$dirshort0 = $val1;

$comicon = “http://ponder.peuplies.info/V_0-1/Muraille/Change-comment-icon/comment_icon_change.txt”;
$fh1 = fopen($comicon, ‘r’);
$outputt1 = fgets($fh1);
$output1 = str_replace(“../..”, “http://ponder.peuplies.info/V_0-1”, $outputt1 );
fclose($fh1);

$dir_handle = @opendir($path) or die(“Unable to open $path”);
$image_table = “<table valign=”top” align=”center” width=”100%”>n”;
$image_table .= “n<tr><td bgcolor=”#cccccc” align=”center” colspan=”3″><table valign=”top” align=”center” width=”100%” border=”0″ cellspacing=”0″>n”;
$image_table .= “n<tr><td bgcolor=”#000033″ class=” white00″ align=”left”><b class=”white00″>Photos in – Photos dans :</b> $dirshort</td>”;
$image_table .= “n <td bgcolor=”#000033″ align=”right” ><br></td></tr>n”;
$image_table .= “n<tr><td bgcolor=”#cccccc” class=” white00″ align=”right” colspan=”2″>n”;
$image_table .= “<script type=”text/javascript”>ajaxinclude(“http://ponder.peuplies.info/V_0-1/Muraille/Change-shoppingcart-button/change_shoppingcart_button.txt”)</script>”;
$image_table .= “n</td></tr>n”;
$image_table .= “n</table><tr>n”;
while (false !== ($file = readdir($dir_handle))) {
if(in_array(substr($file,-4,4),$show)){
if(!(($image_counter + 1) % 3)){
$row_counter++;
}

$newpath0 = substr($file,0,-4);
$newpath00 = substr($file,0,-4);

$image_table .=(($image_counter + 1) % 3)? “” : “</tr>n<tr><td><br></td></tr><tr valign=”top”>”;
$image_table .= “n<td valign=”top” width=”180″><table width=”180″ border=”0″ cellpadding=”0″ cellspacing=”1″ align=”center”>n”;
$image_table .= “n<tr><td valign=”top” bgcolor=”#ffff00″ width=”180″><table width=”180″ border=”0″ cellpadding=”1″ cellspacing=”0″ align=”center”>n”;
$image_table .= “n<tr><td valign=”top” bgcolor=”#003366″ width=”180″><table width=”180″ border=”0″ cellpadding=”1″ cellspacing=”0″ align=”center”>n”;
$image_table .= “n<tr><td bgcolor=”#000033″ align=”center”width=”180″><b>$newpath0</b></td></tr>n”;
$image_table .= “n<tr><td bgcolor=”#000000″ width=”180″><a href=’http://ponder.peuplies.info/V_0-1/Art/$path2$file’ target=’_blank’ rel=”thumbnail”><img src=”http://ponder.peuplies.info/V_0-1/Art/$path$file” width=”180″ border=”0″></a></td></tr>n”;
$image_table .= “n<tr><td bgcolor=”#000033″ align=”center” width=”180″><IMG SRC=”http://ponder.peuplies.info/V_0-1/Art/minus.gif” CLASS=”showstate” ONCLICK=”expandcontent(this, ‘sc”.$newpath0.”‘)” align=”right”><b>Information</b></td></tr>n”;
$image_table .= “n</table>n”;
$image_table .= “n<div id=”sc”.$newpath0.”” class=”switchcontent” width=”180″>n”;
$image_table .= “n<table border=0 align=center cellspacing=0 cellpading=0 width=”180″>n”;
$image_table .= “n<tr><td bgcolor=”#ffffff” align=”left” class=”black0″ width=”180″><b class=”black0″ width=”180″>Description :<br></b><script type=”text/javascript”>ajaxinclude(“http://ponder.peuplies.info/V_0-1/Art/Pictures/Pics/Commentaires/$newpath0.txt”)</script></td></tr>n”;
$image_table .= “n<tr><td bgcolor=”#ffffff” align=”left” class=”black0″ width=”180″><br></td></tr>n”;
$image_table .= “n<tr><td valign=”top” bgcolor=”#ffffff” width=”180″><table width=”180″ border=”0″ cellpadding=”1″ cellspacing=”0″ align=”center”>n”;
$image_table .= “<tr><td bgcolor=”#ffffff” align=”left” width=”180″ valign=”top”><a href=”http://ponder.peuplies.info/V_0-1/Art/rater0.php?var1=$newpath0&var00=$path$file” target=”autre” title=”Rate it! – Noter la !” alt=”Rate it!” class=”black000″><script type=”text/javascript”>ajaxinclude(“http://ponder.peuplies.info/V_0-1/Art/rater1.php?var1=$newpath0&var00=$path$file”)</script></a></td>”;
$image_table .= “n<td bgcolor=”#ffffff” align=”center” class=”black0″ width=”180″ colspan=”2″><script type=”text/javascript”>ajaxinclude(“http://ponder.peuplies.info/V_0-1/Art/Pictures/Pics/Prix/$newpath0.txt”)</script><script type=”text/javascript”>ajaxinclude(“http://ponder.peuplies.info/V_0-1/Art/Pictures/Pics/Vente/$newpath0.txt”)</script></td></tr>n”;
$image_table .= “n</table>n”;
$image_table .= “n<tr><td valign=”top” bgcolor=”#ffffff” width=”180″><table width=”100%” border=”0″ cellpadding=”0″ cellspacing=”0″ align=”center”>n”;
$image_table .= “n<tr><td bgcolor=”#ffffff” align=”left” width=”180″><a href=”http://ponder.peuplies.info/V_0-1/Art/commentaires.php?var001=$newpath0&var002=$path$file” target=”autre” title=”Add comments – Ajout de commentaires.” alt=”Add comments – Ajout de commentaires” class=”white000″><img src=””.$output1.”” border=”0″></a></td>”;
$image_table .= “</td></tr>n”;
$image_table .= “n</table>n”;
$image_table .= “n</div>n”;
$image_table .= “n</table>n”;
$image_table .= “n</table>n”;
$image_table .= “n</table></td>nnn”;

++$image_counter;
++$cell_counter;
}
}
$colspan= ($row_counter * 3) – $cell_counter;
$image_table .= ($cell_counter % 3) ? “<td colspan=$colspan valign=top>&nbsp;</td>” : “”;
$image_table .= “</tr>n</table>n”;
echo “$image_table<br><br>”;

?>

[/code]

This code read a given directory and output image with info formated in rows of 3.

Now I need that the code after 4 row would create a link to go to the nexts images.

Thanks !

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@PeuplarchieauthorNov 12.2007 — I don't use sql..
Copy linkTweet thisAlerts:
@UI-ZEIKVKNov 12.2007 — Chekout this...



[code=php]
<?php
$image_counter = -1;
$row_counter = 0;
$cell_counter = 0;
$i=0;
$show=array('.jpg','.JPG','.gif','.GIF');

$val= $_GET['folder'];
$val1 = $_GET['folder'];
$val0 = $val1;
$val.="/";

$path = "$val";
$path2 = str_replace("Pic-S", "Pic-B", $val);
$dirshort = substr($val,20);
$dirshort0 = $val1;

$comicon = "http://ponder.peuplies.info/V_0-1/Muraille/Change-comment-icon/comment_icon_change.txt";
$fh1 = fopen($comicon, 'r');
$outputt1 = fgets($fh1);
$output1 = str_replace("../..", "http://ponder.peuplies.info/V_0-1", $outputt1 );
fclose($fh1);




$dir_handle = @opendir($path) or die("Unable to open $path");
$image_table = "<table valign="top" align="center" width="100%">n";
$image_table .= "n<tr><td bgcolor="#cccccc" align="center" colspan="3"><table valign="top" align="center" width="100%" border="0" cellspacing="0">n";
$image_table .= "n<tr><td bgcolor="#000033" class=" white00" align="left"><b class="white00">Photos in - Photos dans :</b> $dirshort</td>";
$image_table .= "n <td bgcolor="#000033" align="right" ><br></td></tr>n";
$image_table .= "n<tr><td bgcolor="#cccccc" class=" white00" align="right" colspan="2">n";
$image_table .= "<script type="text/javascript">ajaxinclude("http://ponder.peuplies.info/V_0-1/Muraille/Change-shoppingcart-button/change_shoppingcart_button.txt")</script>";
$image_table .= "n</td></tr>n";
$image_table .= "n</table><tr>n";
while (false !== ($file = readdir($dir_handle))) {
if(in_array(substr($file,-4,4),$show)){
if(!(($image_counter + 1) % 3)){
$row_counter++;
}


$newpath0 = substr($file,0,-4);
$newpath00 = substr($file,0,-4);

$image_table_arr[$i] .=(($image_counter + 1) % 3)? "" : "</tr>n<tr><td><br></td></tr><tr valign="top">";
$image_table_arr[$i] .= "n<td valign="top" width="180"><table width="180" border="0" cellpadding="0" cellspacing="1" align="center">n";
$image_table_arr[$i] .= "n<tr><td valign="top" bgcolor="#ffff00" width="180"><table width="180" border="0" cellpadding="1" cellspacing="0" align="center">n";
$image_table_arr[$i] .= "n<tr><td valign="top" bgcolor="#003366" width="180"><table width="180" border="0" cellpadding="1" cellspacing="0" align="center">n";
$image_table_arr[$i] .= "n<tr><td bgcolor="#000033" align="center"width="180"><b>$newpath0</b></td></tr>n";
$image_table_arr[$i] .= "n<tr><td bgcolor="#000000" width="180"><a href='http://ponder.peuplies.info/V_0-1/Art/$path2$file' target='_blank' rel="thumbnail"><img src="http://ponder.peuplies.info/V_0-1/Art/$path$file" width="180" border="0"></a></td></tr>n";
$image_table_arr[$i] .= "n<tr><td bgcolor="#000033" align="center" width="180"><IMG SRC="http://ponder.peuplies.info/V_0-1/Art/minus.gif" CLASS="showstate" ONCLICK="expandcontent(this, 'sc".$newpath0."')" align="right"><b>Information</b></td></tr>n";
$image_table_arr[$i] .= "n</table>n";
$image_table_arr[$i] .= "n<div id="sc".$newpath0."" class="switchcontent" width="180">n";
$image_table_arr[$i] .= "n<table border=0 align=center cellspacing=0 cellpading=0 width="180">n";
$image_table_arr[$i] .= "n<tr><td bgcolor="#ffffff" align="left" class="black0" width="180"><b class="black0" width="180">Description :<br></b><script type="text/javascript">ajaxinclude("http://ponder.peuplies.info/V_0-1/Art/Pictures/Pics/Commentaires/$newpath0.txt")</script></td></tr>n";
$image_table_arr[$i] .= "n<tr><td bgcolor="#ffffff" align="left" class="black0" width="180"><br></td></tr>n";
$image_table_arr[$i] .= "n<tr><td valign="top" bgcolor="#ffffff" width="180"><table width="180" border="0" cellpadding="1" cellspacing="0" align="center">n";
$image_table_arr[$i] .= "<tr><td bgcolor="#ffffff" align="left" width="180" valign="top"><a href="http://ponder.peuplies.info/V_0-1/Art/rater0.php?var1=$newpath0&var00=$path$file" target="autre" title="Rate it! - Noter la !" alt="Rate it!" class="black000"><script type="text/javascript">ajaxinclude("http://ponder.peuplies.info/V_0-1/Art/rater1.php?var1=$newpath0&var00=$path$file")</script></a></td>";
$image_table_arr[$i] .= "n<td bgcolor="#ffffff" align="center" class="black0" width="180" colspan="2"><script type="text/javascript">ajaxinclude("http://ponder.peuplies.info/V_0-1/Art/Pictures/Pics/Prix/$newpath0.txt")</script><script type="text/javascript">ajaxinclude("http://ponder.peuplies.info/V_0-1/Art/Pictures/Pics/Vente/$newpath0.txt")</script></td></tr>n";
$image_table_arr[$i] .= "n</table>n";
$image_table_arr[$i] .= "n<tr><td valign="top" bgcolor="#ffffff" width="180"><table width="100%" border="0" cellpadding="0" cellspacing="0" align="center">n";
$image_table_arr[$i] .= "n<tr><td bgcolor="#ffffff" align="left" width="180"><a href="http://ponder.peuplies.info/V_0-1/Art/commentaires.php?var001=$newpath0&var002=$path$file" target="autre" title="Add comments - Ajout de commentaires." alt="Add comments - Ajout de commentaires" class="white000"><img src="".$output1."" border="0"></a></td>";
$image_table_arr[$i] .= "</td></tr>n";
$image_table_arr[$i] .= "n</table>n";
$image_table_arr[$i] .= "n</div>n";
$image_table_arr[$i] .= "n</table>n";
$image_table_arr[$i] .= "n</table>n";
$image_table_arr[$i] .= "n</table></td>nnn";

$i++;
++$image_counter;
++$cell_counter;
}
}
$no_of_images = count($image_table_arr);
$colspan= ($row_counter * 3) - $cell_counter;

$to = 12;
if(isset($_GET['from']))
$from = $_GET['from'];
else
$from = -$no_of_images;
echo $image_table;
$image_table_arr= array_slice($image_table_arr, $from, $to);
echo implode("",$image_table_arr);
$image_table1 .= "</tr>n</table>n";
echo "$image_table1<br><br>";

$paginate = ceil($no_of_images/$to);
echo "Page navigation : ";
for ($i=0;$i<$paginate;$i++)
{
$from_val = $no_of_images-($to*$i);
echo "<a href='".$_SERVER['PHP_SELF']."?folder=$val1&from=-".$from_val."'>".($i+1)."</a>&nbsp;&nbsp;&nbsp;";
}

?>


[/code]



Cheers!
Copy linkTweet thisAlerts:
@PeuplarchieauthorNov 12.2007 — Chekout this...



[code=php]
<?php
$image_counter = -1;
$row_counter = 0;
$cell_counter = 0;
$i=0;
$show=array('.jpg','.JPG','.gif','.GIF');

$val= $_GET['folder'];
$val1 = $_GET['folder'];
$val0 = $val1;
$val.="/";

$path = "$val";
$path2 = str_replace("Pic-S", "Pic-B", $val);
$dirshort = substr($val,20);
$dirshort0 = $val1;

$comicon = "http://ponder.peuplies.info/V_0-1/Muraille/Change-comment-icon/comment_icon_change.txt";
$fh1 = fopen($comicon, 'r');
$outputt1 = fgets($fh1);
$output1 = str_replace("../..", "http://ponder.peuplies.info/V_0-1", $outputt1 );
fclose($fh1);




$dir_handle = @opendir($path) or die("Unable to open $path");
$image_table = "<table valign="top" align="center" width="100%">n";
$image_table .= "n<tr><td bgcolor="#cccccc" align="center" colspan="3"><table valign="top" align="center" width="100%" border="0" cellspacing="0">n";
$image_table .= "n<tr><td bgcolor="#000033" class=" white00" align="left"><b class="white00">Photos in - Photos dans :</b> $dirshort</td>";
$image_table .= "n <td bgcolor="#000033" align="right" ><br></td></tr>n";
$image_table .= "n<tr><td bgcolor="#cccccc" class=" white00" align="right" colspan="2">n";
$image_table .= "<script type="text/javascript">ajaxinclude("http://ponder.peuplies.info/V_0-1/Muraille/Change-shoppingcart-button/change_shoppingcart_button.txt")</script>";
$image_table .= "n</td></tr>n";
$image_table .= "n</table><tr>n";
while (false !== ($file = readdir($dir_handle))) {
if(in_array(substr($file,-4,4),$show)){
if(!(($image_counter + 1) % 3)){
$row_counter++;
}


$newpath0 = substr($file,0,-4);
$newpath00 = substr($file,0,-4);

$image_table_arr[$i] .=(($image_counter + 1) % 3)? "" : "</tr>n<tr><td><br></td></tr><tr valign="top">";
$image_table_arr[$i] .= "n<td valign="top" width="180"><table width="180" border="0" cellpadding="0" cellspacing="1" align="center">n";
$image_table_arr[$i] .= "n<tr><td valign="top" bgcolor="#ffff00" width="180"><table width="180" border="0" cellpadding="1" cellspacing="0" align="center">n";
$image_table_arr[$i] .= "n<tr><td valign="top" bgcolor="#003366" width="180"><table width="180" border="0" cellpadding="1" cellspacing="0" align="center">n";
$image_table_arr[$i] .= "n<tr><td bgcolor="#000033" align="center"width="180"><b>$newpath0</b></td></tr>n";
$image_table_arr[$i] .= "n<tr><td bgcolor="#000000" width="180"><a href='http://ponder.peuplies.info/V_0-1/Art/$path2$file' target='_blank' rel="thumbnail"><img src="http://ponder.peuplies.info/V_0-1/Art/$path$file" width="180" border="0"></a></td></tr>n";
$image_table_arr[$i] .= "n<tr><td bgcolor="#000033" align="center" width="180"><IMG SRC="http://ponder.peuplies.info/V_0-1/Art/minus.gif" CLASS="showstate" ONCLICK="expandcontent(this, 'sc".$newpath0."')" align="right"><b>Information</b></td></tr>n";
$image_table_arr[$i] .= "n</table>n";
$image_table_arr[$i] .= "n<div id="sc".$newpath0."" class="switchcontent" width="180">n";
$image_table_arr[$i] .= "n<table border=0 align=center cellspacing=0 cellpading=0 width="180">n";
$image_table_arr[$i] .= "n<tr><td bgcolor="#ffffff" align="left" class="black0" width="180"><b class="black0" width="180">Description :<br></b><script type="text/javascript">ajaxinclude("http://ponder.peuplies.info/V_0-1/Art/Pictures/Pics/Commentaires/$newpath0.txt")</script></td></tr>n";
$image_table_arr[$i] .= "n<tr><td bgcolor="#ffffff" align="left" class="black0" width="180"><br></td></tr>n";
$image_table_arr[$i] .= "n<tr><td valign="top" bgcolor="#ffffff" width="180"><table width="180" border="0" cellpadding="1" cellspacing="0" align="center">n";
$image_table_arr[$i] .= "<tr><td bgcolor="#ffffff" align="left" width="180" valign="top"><a href="http://ponder.peuplies.info/V_0-1/Art/rater0.php?var1=$newpath0&var00=$path$file" target="autre" title="Rate it! - Noter la !" alt="Rate it!" class="black000"><script type="text/javascript">ajaxinclude("http://ponder.peuplies.info/V_0-1/Art/rater1.php?var1=$newpath0&var00=$path$file")</script></a></td>";
$image_table_arr[$i] .= "n<td bgcolor="#ffffff" align="center" class="black0" width="180" colspan="2"><script type="text/javascript">ajaxinclude("http://ponder.peuplies.info/V_0-1/Art/Pictures/Pics/Prix/$newpath0.txt")</script><script type="text/javascript">ajaxinclude("http://ponder.peuplies.info/V_0-1/Art/Pictures/Pics/Vente/$newpath0.txt")</script></td></tr>n";
$image_table_arr[$i] .= "n</table>n";
$image_table_arr[$i] .= "n<tr><td valign="top" bgcolor="#ffffff" width="180"><table width="100%" border="0" cellpadding="0" cellspacing="0" align="center">n";
$image_table_arr[$i] .= "n<tr><td bgcolor="#ffffff" align="left" width="180"><a href="http://ponder.peuplies.info/V_0-1/Art/commentaires.php?var001=$newpath0&var002=$path$file" target="autre" title="Add comments - Ajout de commentaires." alt="Add comments - Ajout de commentaires" class="white000"><img src="".$output1."" border="0"></a></td>";
$image_table_arr[$i] .= "</td></tr>n";
$image_table_arr[$i] .= "n</table>n";
$image_table_arr[$i] .= "n</div>n";
$image_table_arr[$i] .= "n</table>n";
$image_table_arr[$i] .= "n</table>n";
$image_table_arr[$i] .= "n</table></td>nnn";

$i++;
++$image_counter;
++$cell_counter;
}
}
$no_of_images = count($image_table_arr);
$colspan= ($row_counter * 3) - $cell_counter;

$to = 12;
if(isset($_GET['from']))
$from = $_GET['from'];
else
$from = -$no_of_images;
echo $image_table;
$image_table_arr= array_slice($image_table_arr, $from, $to);
echo implode("",$image_table_arr);
$image_table1 .= "</tr>n</table>n";
echo "$image_table1<br><br>";

$paginate = ceil($no_of_images/$to);
echo "Page navigation : ";
for ($i=0;$i<$paginate;$i++)
{
$from_val = $no_of_images-($to*$i);
echo "<a href='".$_SERVER['PHP_SELF']."?folder=$val1&from=-".$from_val."'>".($i+1)."</a>&nbsp;&nbsp;&nbsp;";
}

?>


[/code]



Cheers![/QUOTE]







Wow it work perfectly !!!!

Thanks !

I'll learn from this !!!!

Take care !

Have a nice day !
Copy linkTweet thisAlerts:
@UI-ZEIKVKNov 12.2007 — You are welcome!
Copy linkTweet thisAlerts:
@PeuplarchieauthorNov 12.2007 — Do you think it can display the previous and next ?
Copy linkTweet thisAlerts:
@PeuplarchieauthorNov 12.2007 — How can I show on which page i'm on ?
×

Success!

Help @Peuplarchie spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...