# pagination by alphabetical order with PHP



## tech1tech (Sep 21, 2005)

Hi, could someone kindly help me with this? I need to find a way to paginate my website to categorize names alphabetically. For instance, near the top of the page, there will be links such as "A | B | C | D |.....| Z |". If someone clicks on the "A" link, it will bring up a page with all names beginning with the letter "A". 

Below is my complete code listing for my telephone directory:

<?

session_start();
include_once ("config_dir/config.php");

include ("themes/".$setts['default_theme']."/header.php");

header5("PEOPLE DIRECTORY"); 

if ($_GET['start'] == "") $start = 0;
else $start = $_GET['start'];
$limit = 20;

if ($_GET['search']=="yes"&&trim($_GET['name'])!="") {
$addQuery = " WHERE name LIKE '%".$_GET['name']."%'";
}	
$additionalVars = "&search=".$_GET['search']."&name=".$_GET['name'];

$getPeople = mysql_query("SELECT * FROM people_directory".$addQuery) or die(mysql_error());
$getPeople2 = mysql_query("SELECT * FROM people_directory") or die(mysql_error());
$totalPeople = getSqlNumber("SELECT id FROM people_directory".$addQuery);
$isPeople = mysql_num_rows($getPeople);
if ($isPeople>0) { 
?>
<br>
<table border="0" cellspacing="2" cellpadding="4" class="border"> 
<tr> 
<td nowrap bgcolor="#F3E586">Browse People </td> 
<form name="peoplebrowse" method="get" action="<?=$path;?>people.php"> 
<td bgcolor="#F3E586"><select name="id" onChange="javascripteoplebrowse.submit()" style="font-size: 10px;"> 
<option value="" selected> Select a Person </option> 
<? while($dpeople=mysql_fetch_array($getPeople2)) { ?> 
<option value="<?=$dpeople['id'];?>" <? echo (($dpeople['id']==$_REQUEST['id'])?"selected":"");?>> 
<?=$dpeople['name'];?> 
</option> 
<? } ?> 
</select> </td> 
</form> 
</tr> 
</table> 
<br> 
<table width="100%" border="0" align="center" cellpadding="2" cellspacing="2" class="border"> 
<? while ($people = mysql_fetch_array($getPeople)) { ?> 
<tr class="<? echo (($count++)%2==0) ? "c2":"c3"; ?>"> 
<td><table width="100%" border="0" cellspacing="2" cellpadding="4" class="border"> 
<tr> 
<td colspan="2" class="c1"> <table width="100%" border="0" cellspacing="1" cellpadding="1"> 
<tr class="Subscription"> 
<td><img src="themes/<?=$setts['default_theme'];?>/img/menu_item.gif" width="12" height="12" align="absmiddle" vspace="1"></td> 
<td nowrap><a href="people.php?id=<?=$people['id'];?>"><strong> 
<?=$people['name'];?> 
</strong></a></td> 
<td width="100%" align="right">[ <a href="people.php?id=<?=$people['id'];?>"><strong>details</strong></a> ]</td> 
</tr> 
</table></td> 
</tr> 
<tr> 
<td valign="top"><a href="people.php?id=<?=$people['id'];?>"><img src="<? echo (($people['picture_url']!="")?"makethumb.php?pic=".$people['picture_url']."&w=80&sq=Y":"themes/".$setts['default_theme']."/img/system/noimg.gif");?>" border="0"></a></td> 
<td width="100%" valign="top"><?=addSpecialChars($people['shortdesc']);?> 
<br> 
<br> 
<span class="contentfont"> <a href="categories.php?parent=<?=$people['category_link'];?>">Job Search</a> | <a href="stores.php">Profile</a> | <a href="categories.php?id=1824">Subscription</a> | <a href="wanted.categories.php?parent=<?=$people['category_link'];?>">Jobs Wanted</a> </span></td> 
</tr> 
</table></td> 
</tr> 
<? } ?> 
<tr> 
<td align="center" class="contentfont c4"><? paginate($start,$limit,$totalPeople,"people_directory.php",$additionalVars); ?></td> 
</tr> 
</table> 
<? } else echo "<p align=\"center\">There are people listed at the moment.</p>";
include ("themes/".$setts['default_theme']."/footer.php"); ?> 

--------- END OF CODE ------------

Currently, I just have number pagination at the bottom of the page. However, I want to incorporate alphabetical pagination near the top of the page.

Any help is greatly appreciated. Thank you in advance.

Tech1Tech


----------

