Location: PHPKode > scripts > Php AddressBook 2 > php-addressbook-2/view.php
<div id="datatable">
<? 
//////////////////////////////////////////////////////////////////////////////////
// Select Detail Views
//////////////////////////////////////////////////////////////////////////////////
if (isset($groupe)){
echo "Details:  <a href='index2.php?title=view&groupe=".$groupe."'>Quick</a>  <a href='index2.php?title=view&groupe=".$groupe."&fulldetail=true'>Full</a>";
}

if (isset($alphabet)){
echo "Details:  <a href='index2.php?title=view&alphabet=".$alphabet."'>Quick</a>  <a href='index2.php?title=view&alphabet=".$alphabet."&fulldetail=true'>Full</a>";
}

if (isset($pageid)){
echo "Details:  <a href='index2.php?title=view&pageid=".$pageid."'>Quick</a>  <a href='index2.php?title=view&pageid=".$pageid."&fulldetail=true'>Full</a>";
}

if (!isset($alphabet)){
	if (!isset($groupe)){
		if (!isset($pageid)){
			echo "Details:  <a href='index2.php?title=view'>Quick</a>  <a href='index2.php?title=view&fulldetail=true'>Full</a>";
		}
	}
}

//////////////////////////////////////////////////////////////////////////////////
// Table to open for alphabet listing
//////////////////////////////////////////////////////////////////////////////////

if (isset($alphabet)){ 
		// Get only one column(id) from table.
		$result=mysql_query("SELECT * FROM addressbook WHERE LEFT(firstname,1) = '$alphabet' ORDER BY firstname ASC, lastname ASC");
		} else {
		// Get only one column(id) from table.
		$result=mysql_query("SELECT * FROM addressbook ORDER BY firstname ASC, lastname ASC");
		}

//let's get the number of rows in our result so we can use it in a for loop
$totalrecord = mysql_num_rows($result);

// How many pages will be. Set it to $totalpage.
$totalpage=(int)($totalrecord/$pagesize);
if(($totalrecord%$pagesize)!=0){
$totalpage+=1;
}

/* If this page get $pageid variable, set $pageid and starting record as $start.
If not, $pageid set to 1 and $start set at 0 (first record in table) */
if(isset($pageid)){
$start=$pagesize*($pageid-1);
}
else{
$pageid=1;
$start=0;
}

//////////////////////////////////////////////////////////////////////////////////
// MySQL to execute based on sort peramiters
//////////////////////////////////////////////////////////////////////////////////

// Alpha listing
if ( isset($alphabet) ) {	
 $sql = "SELECT * FROM addressbook WHERE LEFT(firstname,1) = '$alphabet' ORDER BY firstname ASC, lastname ASC limit $start, $pagesize;";
}
	// setup SQL statement if not alpha list
if ( !isset($alphabet) ) {
 $sql = "SELECT * FROM addressbook ORDER BY firstname ASC, lastname ASC limit $start, $pagesize;";
}
// Groupe listing
if ( isset($groupe) ) {	
 $sql = "SELECT addressbook.id, addressbook.gid, addressbook.firstname, addressbook.lastname, addressbook.address, addressbook.postalcode, addressbook.city, addressbook.province, addressbook.country, addressbook.home, addressbook.mobile, addressbook.work, addressbook.work2, addressbook.fax, addressbook.email, addressbook.email2, addressbook.email3, addressbook.yahoo, addressbook.msn, addressbook.icq, addressbook.website, addressbook.profile, addressbook.comments, addressbook.jabber, addressbook.gtalk, addressbook.aim, addressbook.skype, groups.gid, groups.groups FROM addressbook LEFT JOIN groups ON addressbook.gid = groups.gid WHERE groups.gid = $groupe ORDER BY addressbook.firstname ASC;"; 
}

// Use active SQL Query string
$rs = mysql_query($sql) or die ("Query failed");


//////////////////////////////////////////////////////////////////////////////////
// Display Group Listing
//////////////////////////////////////////////////////////////////////////////////

// Groupe Location for sorting data
$glink = "?title=view&groupe";

echo "<div class=\"barLetters\">
<select name=\"groupe\" ONCHANGE=\"location = this.options[this.selectedIndex].value;\">
<option>Select a Groupe</option>";
// Connect to the groups table to get data
 # setup SQL statement
    $sql = "SELECT * FROM groups ORDER BY groups ASC";

    # execute SQL statement
    $grs = mysql_query($sql, $cid);
    if (mysql_error()) { print "Database Error: $sql " . mysql_error(); }

    # execute SQL statement
$grs = mysql_query($sql) or die ("Query failed");
//let's get the number of rows in our result so we can use it in a for loop
$numofrows = mysql_num_rows($grs);
			
for($i = 0; $i < $numofrows; $i++) {
    $row = mysql_fetch_array($grs); //get a row from our result set
	
		include("rows.php"); 
			
		# Output
		echo "<option value='$glink=$gid'>$groups</option>";
		
} // End for
	echo "
</select>
";

//////////////////////////////////////////////////////////////////////////////////
// Display Alphabet Listing
//////////////////////////////////////////////////////////////////////////////////
// Link Location for sorting data
$link = "?title=view&alphabet";

echo "
<select name=\"alphabitGroupe\" ONCHANGE=\"location = this.options[this.selectedIndex].value;\">
<option>Select a Letter</option>
<option value='?title=view'>All</option>
<option value='$link=a'>A</option>
<option value='$link=b'>B</option>
<option value='$link=c'>C</option>
<option value='$link=d'>D</option>
<option value='$link=e'>E</option>
<option value='$link=f'>F</option>
<option value='$link=g'>G</option>
<option value='$link=h'>H</option>
<option value='$link=i'>I</option>
<option value='$link=j'>J</option>
<option value='$link=k'>K</option>
<option value='$link=l'>L</option>
<option value='$link=m'>M</option>
<option value='$link=n'>N</option>
<option value='$link=o'>O</option>
<option value='$link=p'>P</option>
<option value='$link=q'>Q</option>
<option value='$link=r'>R</option>
<option value='$link=s'>S</option>
<option value='$link=t'>T</option>
<option value='$link=u'>U</option>
<option value='$link=v'>V</option>
<option value='$link=w'>W</option>
<option value='$link=x'>X</option>
<option value='$link=y'>Y</option>
<option value='$link=z'>Z</option>
</select>
</div>";

//////////////////////////////////////////////////////////////////////////////////
// Display results
//////////////////////////////////////////////////////////////////////////////////
for( $i = 0; $i < $row = mysql_fetch_array($rs); $i++){ // get a row from our result set

		include("rows.php"); 
		
		$address_array = array("$address", "$city", "$province", "$country");
		
    if($i % 2) { // this means if there is a remainder
        echo "<div id=\"addressChunkOdd\">\n";}
     else { // if there isn't a remainder we will do the else
        echo "<div id=\"addressChunkEven\">\n";}
    ?>
<div id="imageChunk"><a href="?title=fullview&id=<? echo "$id"?>" title="view">
  <h1><? echo "$firstname"?> <? echo "$lastname"?></h1>
  </a>
  <? if(!$profile == '') echo "<a href=\"?title=fullview&id=$id\" title=\"view\"><img src=profiles/imagethumb.php?s=$profile&w=75></a>"; ?>
  <br />
  <div id="modify">
    <div class="barLeft-icon"><a href="?title=delete&id=<? echo "$id"?>" title="Delete"><img src="images/icons/delete.png" alt="Delete" width="16" height="16" /></a></div>
    <div class="barLeft-icon"><a href="?title=edit&id=<? echo "$id"?>" title="Edit"><img src="images/icons/edit.png" alt="Edit" width="16" height="16" /></a></div>
    <div class="barLeft-icon">
      <? if(!$email == '') { 
		echo "<a class=\"email\" href=\"mailto:$email\" title=\"Email\"><img src=\"images/icons/email.png\" alt=\"view\" width=\"16\" height=\"14\" /></a>"; 
		} else {
		echo "<img src=\"images/icons/email-off.png\" alt='Email Off' title='Email Off' width=\"16\" height=\"14\" />";
		} ?>
    </div>
    <div class="barLeft-icon">
      <? if(!$website == '') { 
		echo "<a class=\"url fn\" href=\"$website\"><img src=\"images/icons/world.png\" alt=\"view\" width=\"16\" height=\"16\" /></a>"; 
		} else {
		echo "<img src=\"images/icons/world-off.png\" alt='WWW Off' title='WWW Off' width=\"16\" height=\"16\" />";
		} ?>
    </div>
    <div class="barLeft-icon"><a href="vcard.php?id=<? echo "$id"?>" title="Vcard"><img src="images/icons/v-card.png" alt="View" width="16" height="14" /></a></div>
    <div class="barLeft-icon">
      <? if(!$address == '') {	  
		echo "<a href='?title=google&id=".$id."'><img border=0 src=images/icons/car.png width=16 height=16 title='Google Maps' alt='googlemaps'/></a>"; 
		} else {
		echo "<img border=0 src=images/icons/car-off.png width=16 height=16 title='Google Maps Off' alt='googlemaps'/>";
		} ?>
    </div>
  </div>
</div>
<? if (!isset($fulldetail)){ ?>
<div id="vcard">
  <? if (!$home == '') echo "<strong>Home Phone</strong>: <span class=\"tel\">$home</span><br />" ?>
  <? if (!$mobile == '') echo "<strong>Mobile</strong>: <span class=\"tel\">$mobile</span><br />" ?>
  <? if (!$work == '') echo "<strong>Work</strong>: <span class=\"tel\">$work</span><br />" ?>
  <? if (!$work2 == '') echo "<strong>Work2</strong>: <span class=\"tel\">$work2</span><br />" ?>
</div>
<? } // End if is not set (full details)?>
<? if (isset($fulldetail)){ ?>
<div id="vcard">
  <? 
		if (!$address == '') echo "<strong>Address</strong>:<br><span class=\"street-address\"> $address</span><br />";
		if (!$suite == '') echo "suite: <span class=\"street-suite\"> $suite</span><br />";
		if (!$city == '') echo "<span class=\"locality\">$city</span>, <span class=\"region\">$province</span>, <span class=\"postal-code\">$postalcode</span><br/><span class=\"country-name\">$country</span><br />";
		echo "<br />";
		if (!$home == '') echo "<strong>Home Phone</strong>: <span class=\"tel\">$home</span><br />";
		if (!$mobile == '') echo "<strong>Mobile</strong>: <span class=\"tel\">$mobile</span><br />";
		if (!$work == '') echo "<strong>Work</strong>: <span class=\"tel\">$work</span><br />";
		if (!$work2 == '') echo "<strong>Work2</strong>: <span class=\"tel\">$work2</span><br />";
		if (!$fax == '') echo "<strong>Fax</strong>: <span class=\"tel\">$fax</span><br />";
		echo "<br />";
		if (!$email == '') echo "<strong>E-mail</strong>: <a class=\"email\" href=\"mailto:$email\">$email</a><br />";
		if (!$email2 == '') echo "<strong>E-mail2</strong>: <a class=\"email2\" href=\"mailto:$email2\">$email2</a><br />";
		if (!$email3 == '') echo "<strong>E-mail3</strong>: <a class=\"email3\" href=\"mailto:$email3\">$email3</a><br />";
		echo "<br />";
		if (!$yahoo == '') echo "<strong>Yahoo</strong>: $yahoo<br />";
		if (!$msn == '') echo "<strong>MSN</strong>: $msn<br />";
		if (!$icq == '') echo "<strong>ICQ</strong>: $icq<br />";
		if (!$jabber == '') echo "<strong>Jabber</strong>: $jabber<br />";
		if (!$gtalk == '') echo "<strong>Google Talk</strong>: $gtalk<br />";
		if (!$aim == '') echo "<strong>AIM</strong>: $aim<br />";
		if (!$skype == '') echo "<strong>Skype</strong>: $skype<br />";
		echo "<br />";
		// Gather the Groupe information from the Groupe Table
               # setup SQL statement to retrieve link that we want to edit
                $sql  = " SELECT * FROM groups WHERE gid = $gid ";
                
                # execute SQL statement
                $result = mysql_query($sql,$cid);
        
                # retrieve values
                $row = mysql_fetch_array($result);
                $gid = $row["gid"];
                $groups = $row["groups"];
                    
            echo "<strong>Groupe</strong>: $groups<br />";
            
    echo "<br />";
    if (!$comments == '') print "<strong>Comments</strong>: <div id='barComments'>$comments</div>";
  echo "</div>";

	 } // End for loop
  
	echo "</div><div class='clearfix'></div>\n";
} // End if isset (full details)
?>
</div>
<div class="clearfix"></div>
<div id="perpage-bump"></div>
<div id="perpage">
  <? 
//////////////////////////////////////////////////////////////////////////////////
// Display Per-Page navigation
//////////////////////////////////////////////////////////////////////////////////  
if ( !isset($groupe) ) {
	echo "  Page: ";
	// This is the Page Navigator.
	for ($i=1; $i<=$totalpage; $i++){
	if ($i==$pageid){
		echo "<span class='perpage-current'>$i</span>&nbsp;&nbsp;";
	} // End if (isset groupe)
else{
	if (isset($alphabet)){ 
			// Print Alpha list ontop of Page Navigation.
			echo '<a href='.$PHP_SELF.'?title='.view.'&pageid='.$i.'&alphabet='.$link.'>' .$i.'</a>&nbsp;&nbsp;';		
			} else {
			// Print Paga navigation.
			echo '<a href='.$PHP_SELF.'?title='.view.'&pageid='.$i.'>' .$i.'</a>&nbsp;&nbsp;';
			}
	} // End if (isset alphabet)
}
}
?>
</div>
Return current item: Php AddressBook 2