note 100630 added to control-structures.for

From: Date: Wed, 27 Oct 2010 17:05:28 +0000
Subject: note 100630 added to control-structures.for
Groups: php.notes 
Request: Send a blank email to php-notes+get-173509@lists.php.net to get a copy of this message
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. ---- Server IP: 69.147.83.197 Probable Submitter: 62.80.225.222 ---- Manual Page -- http://www.php.net/manual/en/control-structures.for.php Edit -- https://master.php.net/note/edit/100630 Del: integrated -- https://master.php.net/note/delete/100630/integrated Del: useless -- https://master.php.net/note/delete/100630/useless Del: bad code -- https://master.php.net/note/delete/100630/bad+code Del: spam -- https://master.php.net/note/delete/100630/spam Del: non-english -- https://master.php.net/note/delete/100630/non-english Del: in docs -- https://master.php.net/note/delete/100630/in+docs Del: other reasons-- https://master.php.net/note/delete/100630 Reject -- https://master.php.net/note/reject/100630 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#173509) next »