note 100630 deleted from control-structures.for by danbrown

From: Date: Wed, 27 Oct 2010 17:08:39 +0000
Subject: note 100630 deleted from control-structures.for by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-173510@lists.php.net to get a copy of this message
Note Submitter: Han&#39;i ---- for() can be used for simple non-SQL pagination. In the example below you can see an avatar selection page that I use on my site. In my example it paginates every 10 pages. Note: in this example the avatar names must be numeric! $c=count(glob("./img/avatar/".$to['sex']."/*.*")); #how many avatars are there echo 'Available avatars: <b>'.$c.'</b><br/> Choose a desirable avatar:<br/>'; $pgs=ceil($c/10); #total pages if ($_GET["p"]) $p=$_GET["p"]; else $p=1; if ($p>$pgs) $p=$pgs; if ($p<1) $p=1; #some security in case of wise guys $i=(($p*10)-10); for ($i=$i; $i<$p*10; $i++) { if ($i<$c) echo '<a href="./?act=edit&what=avvy&av='.$i.'"> <img src="./img/avatar/'.$to["sex"].'/'.$i.'.gif" alt="x" width="50" height="50"/></a> '; } echo '<br/>'; if ($p>1) echo '<a href="./?act=edit&what=avvy&p='.($p-1).'">Prev</a>'; echo ' '; if ($p<$pgs) echo '<a href="./?act=edit&what=avvy&p='.($p+1).'&id='.$id.'">Next</a>'; echo '<br/>p='.$p.' pgs='.$pgs.'<br/>'; #remove this line in your script, it's just for testing.

« previous php.notes (#173510) next »