Location: PHPKode > scripts > PHP Address book > php-address-book_v_1.01_eng/php-address-book_v_1.01_eng/overview.php
<?php 
include_once 'includes/header.inc.php';

if(!$session->getRole() == 1 or !$session->getRole() == 2){
    header("location: login.php");
}

//see if there is a beginletter
if(isset($_GET['q'])){
    $q = $database->escape($_GET['q']);
    $q = $q . "%";
} else {
    $q = "%";
}

//count total records
$query = $database->query("SELECT * FROM `cal_contacts` WHERE `cal_contacts`.`firstname` LIKE '$q'");
$total = mysql_num_rows($query);

?>
<legend>Contacts overview</legend>
<?php
if($total == 0){
    ?>
    <div class="alert alert-info">
        There are no contacts here yet
    </div>
    <?php
} else {
    ?>
    <table class="table table-striped">
        <tr>
            <th>Firstname</th>
            <th>Lastname</th>
            <th>E-mail</th>
            <th>Birthday</th>
            <th>Age</th>
        </tr>
    <?php
    //check if there is a start
    if(isset($_GET['start'])){
        $start = $database->escape($_GET['start']);
    } else {
        $start = 0;
    }

    $limit = 15;


    $query = $database->query("SELECT `cal_contacts`.*, EXTRACT(YEAR FROM (FROM_DAYS(DATEDIFF(NOW(),`birthday`))))+0 AS `age`, DATE_FORMAT(`cal_contacts`.`birthday`, '%d') AS `date`, DATE_FORMAT(`cal_contacts`.`birthday`, '%m') AS `month`, DATE_FORMAT(`cal_contacts`.`birthday`, '%Y') AS `year` FROM `cal_contacts` WHERE `cal_contacts`.`firstname` LIKE '$q' ORDER BY `firstname` LIMIT $start, $limit");
    while($row = mysql_fetch_assoc($query)){
        ?>
        <tr>
            <td><a href="<?php echo $url; ?>details.php?id=<?php echo $row['id']; ?>"><?php echo $row['firstname']; ?></a></td>
            <td><?php echo $row['lastname']; ?></td>
            <td><?php if($row['email'] != ""){ echo $row['email']; } else { echo "Onbekend"; } ?></td>
            <td><?php if($row['date'] != "00"){ echo $row['date'] . " - " . $row['month']; } else { echo "Unknown"; } ?></td>
            <?php if($row['year'] == "0000"){
                ?><td>Unknown</td><?php
            } else {
                ?><td><?php echo $row['age']; ?></td><?php
            }
            ?>
        </tr>
        <?php
    }
    ?></table>
<div class="pagination">
  <ul>
      
    <?php if($start != 0){ ?>
        <li><a href="?start=<?php echo $start-$limit; ?>">Vorige</a></li>
    <?php }
    
        $query = $database->query("SELECT SUBSTR(firstname,1,1) as `shorten` FROM `cal_contacts` GROUP BY `shorten`");
        while($row = mysql_fetch_assoc($query)){
            ?><li><a href="?start=<?php echo $start; ?>&q=<?php echo $row['shorten']; ?>"><?php echo $row['shorten']; ?></a></li><?php
        }
        
    if(($start + $limit) <= $total ){ ?>
        <li><a href="?start=<?php echo $start+$limit; ?>">Volgende</a></li>
    <?php } ?>
  </ul>
</div>
<?php 
}
include_once 'includes/footer.inc.php'; ?>
Return current item: PHP Address book