-5
<?php
// Including data base file for connection
require_once 'config.php';
require 'db.php';
$data = array();
//creating array for alphabet
$navigation = array(
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
);
$rec_limit = 3;
$limit = 3;
if (isset($_GET['page'])) {
$page = $_GET['page'] + 1;
$limit = $page * $limit;
$offset = $limit - 1;
}
else {
$page = 1;
$offset = 0;
}
print "SELECT * FROM user $query LIMIT $offset, $limit";
$query =isset($_GET['alphabet'])? " WHERE lname like '" . $_GET['alphabet'] . "%'":'';
$count_query = mysql_query("SELECT count(*) as count_data FROM user $query");
$result = mysql_query("SELECT * FROM user $query LIMIT $offset, $limit");
$count_data = mysql_fetch_array($count_query);
while ($estrogen_limit_user = mysql_fetch_array($result)) {
$data[] = $estrogen_limit_user;
}
$rec_count = $count_data['count_data'];
$total_page = ceil($rec_count/$rec_limit);
$left_rec = $rec_count - ($page * $rec_limit);
?>
<?php
//alphabet showing on the page
foreach ($navigation as $value) {
?>
<a href="directory.php?alphabet=<?php print $value; ?>"><?php print $value; ?></a>
<?php } ?>
<a href="admin-section.php?alphabet=<?php print $_GET['alphabet'];?>"> Click here for edit the records</a>
<?php
//if data will found from the db
if (count($data) > 0) {
foreach ($data as $row) {
?>
<p class="name"><a href="directoryedit.php?ID=<?php print $row['id']?>"><?php print $row['fname'] . ' ' . $row['lname'];//print fname and lastname ?></a></p>
<p><?php print $row['address'];//print address ?></p>
<p><?php print $row['city']; //print city?></p>
<p><?php print $row['phone']; //print phone?></p>
<p><?php print $row['email']; //print email?></p>
<?php
}
} //if data will not found
else {
print "NOT FOUND";
}
if($page > 1) {
$last = $page - 2;
echo "<a href=\"$_PHP_SELF?page=$last\">Last 3 Records</a>";
if($total_page < $page)
echo "| <a href=\"$_PHP_SELF?page=$page\">Next 3 Records</a>";
}
else if($page == 1) {
echo "<a href=\"$_PHP_SELF?page=1\">Next 3 Records</a>";
}
else if($left_rec < $rec_limit) {
$last = $page - 2;
echo "<a href=\"$_PHP_SELF?page=$last\">Last 3 Records</a>";
}
?>
我已經嘗試了很多,但我無法解決它不能正常工作。 我張貼我的整個頁面的內容,因爲我剛剛開始了我的職業生涯,我在這裏是新的,所以不知道它。 它是我現在工作的項目的目錄頁面。我們如何在php代碼中創建分頁?
什麼是錯誤?它是做什麼的。另一個注意事項是你的代碼容易受到SQL注入的影響 – Cfreak