Home      Products & Services      Contact Us      Links

WebHatchers will design & develop your site for you.

Website Menu Heaven: menus, buttons, etc.

Send us your questions.

site search by freefind

SEO, Google, Privacy
   and Anonymity
Browser Insanity
Popups and Tooltips
Free Website Search
HTML Form Creator
Buttons and Menus
Image Uploading
Website Poll
IM and Texting
   or Not MySQL
Personal Status Boards
Content Management
Article Content
   Management Systems
Website Directory
   CMS Systems
Photo Gallery CMS
Forum CMS
Blog CMS
Customer Records
   Management CMS
Address Book CMS
Private Messaging CMS
Chat Room CMS
JavaScript Charts
   and Graphs

Free Personal Status Boards (PSB™)

Free Standard Free PSB

Free PSB Pro Version

Free Social PSB

Free Social PSB Plus (with Email)

Free Business PSB

Free Business PSB Plus (with Email)

PSB demo

Social PSB demo

Business PSB demo

So what's all this PSB stuff about?

Chart comparing business status boards

PSB hosting diagram

PSB Licence Agreement

Copyright © 2002 -
MCS Investments, Inc. sitemap

PSBs, social networking, social evolution, microcommunities, personal status boards
PSBs, social networking, business personal status boards
website design, ecommerce solutions
website menus, buttons, image rotators
Ez-Architect, home design software
the magic carpet and the cement wall, children's adventure book
the squirrel valley railroad, model railroad videos, model train dvds
the deep rock railroad, model railroad videos, model train dvds

Address Book Sort Contacts By Type

This page is a tutorial on an app page that you use to view your address book sorted by the Relationship Type this contact has with you, and you also use it to work from when you are selecting any of the other address book application functions such as delete, add, edit, or sort by name.

Address Book Sort Contacts By Type

As you'll see above from our test page printout, the app page lets you view the name, relationship type, email (it links to your email client so you can email this contact, automatically using the MySQL field Email1 as the email address) and work phone. Feel free to modify the PHP code and column titles so something else comes up rather than these items. Here are the choices:

Here are the Relationship Types you can choose from when you add a new contact:

The two upper corner buttons get you to the sort by name and add new contact functions. The delete and edit functions are specific to the contact person whose row they are in—there are delete and edit function links on every row. There's no limit to the number of entries, except for when your host screams because your 10 million entry table is taking too long to load or too much space on his server. The fields have character limits—usually 20, 40, or 90, except State and Zip get only 10 each and Notes gets 400, since it's a textarea box with liberal allowances. Bad email addresses will be caught and you will be asked to fix them before you can save. (So dumb@dumber is no good, nor is smelly@smellier.smelliest).

Let us look at the script. The CSS is trivial. The include gets you MySQL access if you created it right. The SELECT * FROM addressbook ORDER BY RelationshipType gets everything in the table into the result set and our script puts just the fields First, Middle, Last, RelationshipType, Email and WorkPhone in the address book display, sorted by the RelationshipType field. Note that Name is composed of three fields. If you ever end up with thousands of contacts, feel free to replace * with First, Middle, Last, RelationshipType, Email1, WorkPhone and also use mysql_fetch_assoc() rather than mysql_fetch_array() (the latter gets both numeric and associative indices, while the associative version gets only associative indices) to speed things up, but MySQL and PHP are fast, so we doubt it will make much practical difference for you. If the table is empty, you get sent to Address Book Add New Contact to add contacts.

The }else{ is the start of the code that is run if the table has data in it. Next we use a simple while loop and the PHP mysql_fetch_array() function to get specific data from the table. This function gets a result row as an associative array, a numeric array, or both if you add special parameters to keep it from defaulting to both array indices being fetched. Since it only gets one row in the array, you need the while loop to get them all. With each row's array, you choose which fields you're interested in by use of such code as this:
echo htmlentities(stripslashes($row['First']), ENT_QUOTES). The stripslashes() function unescapes the data that got escaped for security reasons by the mysql_real_escape_string() function as we originally inserted the data into the MySQL database table. The htmlentities() function makes the data safe to display in a browser just in case some wise guy has stuck in some type of hacker code nonsense. The ENT_QUOTES parameter applies to htmlentities() and will convert both double and single quotes to safer display forms (e.g., ' is changed to ').

Note that we don't display emails—we convert them to links with "Email" as link text. First we get the email into $E, using our htmlentities(stripslashes()) double whammy to make it safe, which was already handled in the email filter routine in Address Book Add New Contact which would never have allowed bad stuff in the email address in the first place. Double protection—ya gotta love it. Notice where the single and double quotes go in this line:
echo "<a href='mailto:".$E."?subject=Address Book Mail'>Email</a>"; . Feel free to change the email subject that will go in the email client Subject box while the email address itself ends up in the To box.

Now check out where quotes are in the following:
echo "<a HREF='address-book-edit.php?id=".$row['id']."'>Edit</a>"; . It can be hard to follow. Make sure to understand what is single and what is double, which is hard to see unless you forward-arrow over the line watching where the cursor jumps to.

So then we finish the table and the div, then close up the database. And that's it.

On to the code for the script. Name the following: address-book-sort-by-type.php

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252">
<TITLE>PHP Address Book — Sort by Type</TITLE>
<meta name="description" content="PHP Address Book — Sort by Type">
<meta name="keywords" content="PHP Address Book,PHP Address Book Sort by Type,Content Management System,cms,javascript, dhtml, DHTML">
<style type="text/css">
BODY {margin-left:0; margin-right:0; margin-top:0;background-color:#cccccc;}
p, li, td {font:13px Verdana; color:black;}
h1 {font:bold 28px Verdana; color:black;text-align:center}
#address {position:absolute; left:50px; top:60px; width:900px; margin:0; padding:10px; background-color:#eee; border:2px solid #000; font:bold 11px Verdana;}
.button1{position:absolute; left:50px; top:26px; width:98px; padding:4px; background-color:#ddd; border:1px solid #000; font:bold 11px Verdana;}
.button2{position:absolute; right:50px; top:26px; width:121px; padding:4px; background-color:#ddd; border:1px solid #000; font:bold 11px Verdana;}
<div class='button1'><a HREF="address-book-sort-by-name.php">Sort by Name</a></div>
<div class='button2'><a HREF="address-book-add.php">Add New Contact</a></div>

$res = mysql_query("SELECT * FROM addressbook ORDER BY RelationshipType") or die(mysql_error());
$rows = mysql_num_rows($res);
if($rows==0){echo '<script language="javascript">alert("Address Book empty. Add contacts."); window.location = "address-book-add.php"; </script>';


echo "<center><h1>PHP Address Book — Sort by Type</h1></center>
<div id='address'><table border='1' width='900'>";
echo "<tr><th>Name</th><th>RelationshipType</th><th>Email</th><th>Work Phone</th><th>Edit</th><th>Delete</th></tr>";
while($row = mysql_fetch_array($res)) {
echo "<tr><td>";
echo htmlentities(stripslashes($row['First']), ENT_QUOTES);
echo " ";
echo htmlentities(stripslashes($row['Middle']), ENT_QUOTES);
echo " ";
echo htmlentities(stripslashes($row['Last']), ENT_QUOTES);
echo "</td><td>";
echo htmlentities(stripslashes($row['RelationshipType']), ENT_QUOTES);
echo "</td><td>";
$E=htmlentities(stripslashes($row['Email1']), ENT_QUOTES);
echo "<a href='mailto:".$E."?subject=Address Book Mail'>Email</a>";
echo "</td><td>";
echo htmlentities(stripslashes($row['WorkPhone']), ENT_QUOTES);
echo "</td><td>";
echo "<a HREF='address-book-edit.php?id=".$row['id']."'>Edit</a>";
echo "</td><td>";
echo "<a HREF='delete-address-book-contact.php?id=".$row['id']."'>Delete</a>";
echo "</td></tr>";

echo "</table></div>";