code for Alphabetical pager class
| From: | austin swinney | Date: | Mon, 25 Feb 2002 22:10:54 +0000 |
| Subject: | code for Alphabetical pager class | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-80395@lists.php.net to get a copy of this message | ||
i think somebody is working on a pager class. this class alpha could
either extend or be incorporated into a pager class. it is composed of
two functions: _getAlphabet() accepts no arguements and returns an array
of the alphabet, getAlphabetNav ($page,$i) accepts (1)the link reference
page and (2) letter that is current (so as to not link it).
the code below returns an multi-dimentional array of html links with
urls that use the value $i=$char[a-z]:
http://www.example.com/users.php?i=m
example of html returned:
<a href='./users.php?i=a'>a</a>
<a href='./users.php?i=b'>b</a>
<a href='./users.php?i=c'>c</a>
<a href='./users.php?i=d'>d</a>
(...)
for example, in use:
<?php
/* get the alphabetical navigation
*/
require("Madmin/Alpha.php");
$a = new Alpha();
$alphNav=$a->getAlphabetNav($PHP_SELF,$i);
/*
* then you can use the alphabetic character to
* do things like sql select statements:
*/
if ($i) {
$query = "SELECT user_id, username, email FROM user WHERE username
LIKE '$i%'";
}
?>
here is the code for the class:
<?php
//$Id: Alpha.php,v 1.4 2002/02/26 01:05:40 austin Exp $
class Alpha {
/**
* get an array of alphabet for use inside the class
*/
function _getAlphabet() {
$_alphabet=array(1 =>
"a","b","c","d","e","f","g","h","i",
"j","k","l","m","n","o","p","q","r",
"s","t","u","v","w","x","y","z");
return $_alphabet;
}
function getAlphabetNav ($page,$i) {
$alphabet=$this->_getAlphabet();
foreach ($alphabet as $key=>$val) {
if ($val!="$i"||!"$i") {
$links .= "<a href='$page?i=$key'>$val</a> ";
} else {
$links .= "$val ";
}
}
return $links;
unset($links);
}
}
?>
comments appreciated :)
austin swinney ___ ___ _
information specialist II /_ / /_> SCZ, CA
Education.Training.Research /__ / / | r r r r r
austins@etr.org pirates of programming