burada benim sayfalama sınıftır. yapı içinde veri sadece db sorguları ve diğer şeyler yapar bir başka sınıf. i yaşıyorum sorun i pagination yazdırmayı maç için veri çıkışı almak için cant olduğunu ve i () verileri sorgulamak ve bunu yazdırmak için mysql_fetch_assoc almak gibi olamaz. ben bu hatayı alıyorum:
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /phpdev/pagination/index.php on line 215
ben bu veriyi almak için sorgu doğru olmadığı anlamına gelebilir biliyorum ama doğru girdiniz. komut biraz uzun olduğu için özür dilerim. i herhangi bir yardım için şimdiden teşekkür ederiz.
<?php
include_once("class.db.php");
mysql_connect("host","login","password");
mysql_select_db("iadcart");
class Pagination {
var $adjacents;
var $limit;
var $param;
var $mPage;
var $query;
var $qData;
var $printData;
protected $db;
function __construct() {
$this->db = new MysqlDB;
}
function show() {
$result = $this->db->query($this->query);
$totalPages = $this->db->num_rows($result);
$limit = $this->limit;
/* -------------------------------------
Set Page
------------------------------------- */
if(isset($_GET['page'])) {
$page = intval($_GET['page']);
$start = ($page - 1) * $limit;
} else {
$start = 0;
}
/* -------------------------------------
Set Page Vars
------------------------------------- */
if($page == 0) {
$page = 1;
}
$prev = $page - 1;
$next = $page + 1;
$lastPage = ceil($totalPages/$limit);
$lpm1 = $lastPage - 1;
$adjacents = $this->adjacents;
$mPage = $this->mPage;
//the magic
$this->qData = $this->query . " LIMIT $start, $limit";
$this->printData = $this->db->query($this->qData);
/* -------------------------------------
Draw Pagination Object
------------------------------------- */
$pagination = "";
if($lastPage > 1) {
$pagination .= "<div class='pagination'>";
}
/* -------------------------------------
Previous Link
------------------------------------- */
if($page > 1) {
$pagination .= "<li><a href='$mPage?page=$prev'> previous </a></li>";
} else {
$pagination .= "<li class='previous-off'> previous </li>";
}
/* -------------------------------------
Page Numbers (not enough pages - just display active page)
------------------------------------- */
if($lastPage < 7 + ($adjacents * 2)) {
for($counter = 1; $counter <= $lastPage; $counter++) {
if($counter == $page) {
$pagination .= "<li class='active'>$counter</li>";
} else {
$pagination .= "<li><a href='$mPage?page=$counter'>$counter</a></li>";
}
}
}
/* -------------------------------------
Page Numbers (enough pages to paginate)
------------------------------------- */
elseif($lastPage > 5 + ($adjacents * 2)) {
//close to beginning; only hide later pages
if($page < 1 + ($adjacents * 2)) {
for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++) {
if ($counter == $page) {
$pagination.= "<li class='active'>$counter</li>";
}
else {
$pagination.= "<li><a href='$mPage?page=$counter'>$counter</a></li>";
}
}
$pagination.= "...";
$pagination.= "<li><a href='$mPage?page=$lpm1'>$lpm1</a></li>";
$pagination.= "<li><a href='$mPage?page=$lastPage'>$lastPage</a></li>";
}
elseif($lastPage - ($adjacents * 2) > $page && $page > ($adjacents * 2)) {
$pagination.= "<li><a href='$mPage?page=1'>1</a></li>";
$pagination.= "<li><a href='$mPage?page=2'>2</a></li>";
$pagination.= "...";
for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++) {
if ($counter == $page) {
$pagination.= "<li class='active'>$counter</li>";
}
else {
$pagination.= "<li><a href='$mPage?page=$counter'>$counter</a></li>";
}
}
$pagination.= "...";
$pagination.= "<li><a href='$mPage?page=$lpm1'>$lpm1</a></li>";
$pagination.= "<li><a href='$mPage?page=$lastPage'>$lastPage</a></li>";
}
else {
$pagination.= "<li><a href='$mPage?page=1'>1</a></li>";
$pagination.= "</li><a href='$mPage?page=2'>2</a></li>";
$pagination.= "...";
for ($counter = $lastPage - (2 + ($adjacents * 2)); $counter <= $lastPage; $counter++) {
if ($counter == $page) {
$pagination.= "<li class='active'>$counter</li>";
}
else {
$pagination.= "<li><a href='$mPage?page=$counter'>$counter</a></li>";
}
}
}
}
/* -------------------------------------
Next Link
------------------------------------- */
if ($page < $counter - 1) {
$pagination.= "<li><a href='$mPage?page=$next'> Next </a></li>";
}
else {
$pagination.= "<li class='next-off'> Next </li>";
$pagination.= "</div>";
}
print $pagination;
}
}
?>
<html>
<head>
</head>
<body>
<table style="width:800px;">
<?php
mysql_connect("localhost","root","games818");
mysql_select_db("iadcart");
$pagination = new pagination;
$pagination->adjacents = 3;
$pagination->limit = 10;
$pagination->param = $_GET['page'];
$pagination->mPage = "index.php";
$pagination->query = "select * from tbl_products where pVisible = 'yes'";
while($row = mysql_fetch_assoc($pagination->printData)) {
print $row['pName'];
}
?>
</table>
<br/><br/>
<?php $pagination->show(); ?>
</body>
</html>