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

?>
<legend>Contacts overview</legend>
<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;
}

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

$limit = 15;

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


$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