Location: PHPKode > projects > PHP MySQL Address Book > addressbook/alphapaging.php
<?php
require("sesionchk.php");
?>
<html>
<head>
<title>
<?php
require("title.php");
?>
</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>

<body>
<?php
require("links.php");
include 'library/config.php';
include 'library/opendb.php';
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td style=" vertical-align: top";>
	</td>
    <td>
<?php
/*
// how many rows to show per page
$rowsPerPage = 20;

// by default we show first page
$pageNum = 1;

// if $_GET['page'] defined, use it as page number
if(isset($_GET['page']))
{
	$pageNum = $_GET['page'];
}

// counting the offset
$offset = ($pageNum - 1) * $rowsPerPage;
*/
//$query  = "SELECT FirstName,EmailAddress,ID FROM contacts LIMIT $offset, $rowsPerPage";
if ($_GET[value]=="all")
{
//$query  = "SELECT FirstName,EmailAddress,ID FROM contacts ORDER BY FirstName  ASC";
$query  = "SELECT FirstName,Company,BusinessPhone,BusinessFax,HomePhone,MobilePhone,Categories,EmailAddress,ID,user_id FROM contacts ORDER BY FirstName  ASC";
}
else
{
//$query  = "SELECT FirstName,EmailAddress,ID FROM contacts where FirstName like '".$_GET[value]."%' ORDER BY FirstName  ASC";
$query  = "SELECT FirstName,Company,BusinessPhone,BusinessFax,HomePhone,MobilePhone,Categories,EmailAddress,ID,user_id FROM contacts where FirstName like '".$_GET[value]."%' ORDER BY FirstName  ASC";
}
mysql_query("SET NAMES 'utf8'");
mysql_query('SET CHARACTER SET utf8'); 
$result = mysql_query($query) or die('Error, query failed');

// print the random numbers
foreach (range('A', 'Z') as $letter) {
	echo " <a href=\"".$_SERVER['PHP_SELF']."?type=sort&value=".$letter."\" class=\"text\">".$letter."</A>  ";
} 
echo " <a href=\"".$_SERVER['PHP_SELF']."?type=sort&value=all\" class=\"text\">All</A> ";

echo "<table border='1' cellpadding='1' cellspacing='1' bordercolor='#000000'> <COLGROUP span='10' width='0*'>";
echo "<tr ><td></td><td>Name</td><td>Company</td><td>Business Phone</td><td>Business Fax</td><td>Home Phone</td><td>Mobile Phone</td><td>Categories</td><td>E-Mail</td><td></td></tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
	echo "<td>";
	if ($_SESSION['usr_level'] <>3 or $_SESSION['usr_id']==$row['user_id'])
	{
	echo "<a href=\"wabraaddressbook.php?ID=".$row['ID']."\">Edit</a>";
	}
	else
	{
	echo "<a href=\"wabraaddressbook.php?ID=".$row['ID']."\">View</a>";
	}
	echo "</td>";
	echo "<td>";
	if (trim($row['FirstName'])!=="")
	{
	echo $row['FirstName'];
	}
	else
	{
	echo"&nbsp;";
	}
	echo "</td>";
	echo "<td>";
	if (trim($row['Company'])!=="")
	{
	echo $row['Company'];
	}
	else
	{
	echo"&nbsp;";
	}
	//echo $row['Company'];
	echo "</td>";
	echo "<td>";
	if (trim($row['BusinessPhone'])!=="")
	{
	echo $row['BusinessPhone'];
	}
	else
	{
	echo"&nbsp;";
	}
//	echo $row['BusinessPhone'];
	echo "</td>";
	echo "<td>";
	if (trim($row['BusinessFax'])!=="")
	{
	echo $row['BusinessFax'];
	}
	else
	{
	echo"&nbsp;";
	}
//	echo $row['BusinessFax'];
	echo "</td>";
	echo "<td>";
	if (trim($row['HomePhone'])!=="")
	{
	echo $row['HomePhone'];
	}
	else
	{
	echo"&nbsp;";
	}
//	echo $row['HomePhone'];
	echo "</td>";
	echo "<td>";
	if (trim($row['MobilePhone'])!=="")
	{
	echo $row['MobilePhone'];
	}
	else
	{
	echo"&nbsp;";
	}
//	echo $row['MobilePhone'];
	echo "</td>";
	echo "<td>";
	if (trim($row['Categories'])!=="")
	{
	echo $row['Categories'];
	}
	else
	{
	echo"&nbsp;";
	}
//	echo $row['Categories'];
	echo "</td>";
	echo "<td>";
	
	if (trim($row['EmailAddress'])!=="")
	{
		echo "<a href='mailto:".trim($row['EmailAddress'])."'>" .trim($row['EmailAddress'])."</a>";
	 }
	 else
	 {
	 echo"&nbsp;";
	 }
	echo "</td>";
	
	echo "<td>";
	if ($_SESSION['usr_level'] <>3 or $_SESSION['usr_id']==$row['user_id'])
	{
	echo "<a href=\"wabraaddressbook.php?ID=".$row['ID']."&salph=".$_GET[value]."&mod=del\">Delete</a>";
	}
	else
	{
	echo "&nbsp;";
	}
	
//	echo "<a href=\"library/delrec.php?ID=".$row['ID']."&salph=".$_GET[value]."\">Delete</a>";
	echo "</td>";
	
	
	/*echo "<td>".$i."</td>";
	$gh=$i+1;
	echo "<td>".$gh."</td>";
	*/
	echo "</tr>";
/*


	echo $row['FirstName'] ." <a href=\"wabraaddressbook.php?ID=".$row['ID']."\">Edit</a> &nbsp; <a href=\"library/delrec.php?ID=".$row['ID']."&salph=".$_GET[value]."\">Delete</a> <br>";
	*/
}
echo '</table>';
/*
// how many rows we have in database
$query   = "SELECT COUNT(FirstName) AS numrows FROM contacts";
$result  = mysql_query($query) or die('Error, query failed');
$row     = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];

// how many pages we have when using paging?
$maxPage = ceil($numrows/$rowsPerPage);

// print the link to access each page
$self = $_SERVER['PHP_SELF'];
$nav = '';
for($page = 1; $page <= $maxPage; $page++)
{
	if ($page == $pageNum)
	{
		$nav .= " $page ";   // no need to create a link to current page
	}
	else
	{
		$nav .= " <a href=\"$self?page=$page\">$page</a> ";
	}		
}

// creating previous and next link
// plus the link to go straight to
// the first and last page

if ($pageNum > 1)
{
	$page = $pageNum - 1;
	$prev = " <a href=\"$self?page=$page\">[Prev]</a> ";
	
	$first = " <a href=\"$self?page=1\">[First Page]</a> ";
} 
else
{
	$prev  = '&nbsp;'; // we're on page one, don't print previous link
	$first = '&nbsp;'; // nor the first page link
}

if ($pageNum < $maxPage)
{
	$page = $pageNum + 1;
	$next = " <a href=\"$self?page=$page\">[Next]</a> ";
	
	$last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> ";
} 
else
{
	$next = '&nbsp;'; // we're on the last page, don't print next link
	$last = '&nbsp;'; // nor the last page link
}

// print the navigation link
echo $first . $prev . $nav . $next . $last;
*/
// and close the database connection
include 'library/closedb.php';
?></td>
  </tr>
</table>

</body>
</html>
Return current item: PHP MySQL Address Book