sakila_db.php
<?php
define('LIMIT', 25);
function getCon(){
$link = mysql_connect('localhost', 'root', '');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
return $link;
}
function getAll($off_set = 0){
$db = mysql_select_db("sakila",getCon());
$result = mysql_query("select * from actor limit {$off_set},".LIMIT);
$data = array();
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$data[] = array(
'id'=>$row['actor_id'],
'firstname'=>$row['first_name'],
'lastname'=>$row['last_name']
);
}
return $data;
}
function getNum(){
$db = mysql_select_db("sakila",getCon());
$result = mysql_query("SELECT * FROM actor");
$total = mysql_num_rows($result);
return $total/LIMIT;
}
?>
actor_list.php
<?php include('sakila_db.php') ?>
<!DOCTYPE html>
<html>
<head>
<title>List of Actor</title>
<style type="text/css">
*{
font-size: 13px;
font-family: arial;
}
table{
border-collapse: collapse;
width: 500px;
}
table tr th,table tr td{
padding: 5px;
}
span a {
padding: 7px;
width: 7px;
height: 7px;
text-decoration: none;
background-color: red;
color:white;
}
</style>
</head>
<body>
<h3>USE [Sakila] Database</h3>
<table border="1">
<tr>
<th>#</th>
<th>Firt Name</th>
<th>Last Name</th>
</tr>
<?php
$offset = 0;
if(isset($_GET['offset'])){
$offset = $_GET['offset'];
}
foreach (getAll($offset) as $key => $value) { ?>
<tr>
<td><?php echo $value['id']; ?></td>
<td><?php echo $value['firstname']; ?></td>
<td><?php echo $value['lastname']; ?></td>
</tr>
<?php } ?>
</table>
<hr/><br/>
<?php
for ($i=0,$j=0; $i < getNum(); $i++,$j+=LIMIT) {
echo "<span> <a href=actor_list.php?offset={$j}>".($i+1)."</a></span>";
}
?>
</body>
</html>
----------------------------------
Sakila Sample Database
Sakila Sample Database
Demo:
0 comments:
Post a Comment