ผมกำลังจะเปลี่ยนเป็น mysql ครับ แต่ว่าติดตรง return loaddoc ของห
ตอนนี้ผมค่อยๆแก้ไปเรื่อยๆแต่มาติดตรง
แบ่งหน้า สติกเก้อ ครับผม
return loaddoc ไม่เปลี่ยนตามหน้าที่ผมกดอะครับผม ผมงงจังเลยครับ >,<
ขออนุญาติแปะ
if ( $page < 1 ) //เริ่มต้นที่หน้าที่ 1
{
$page = 1;
};
if ( !isset( $sortby ) ) //เรียงลำดับโดย id
{
$sortby = 'id';
};
include("hi5db.php");
$adjacents = 3;
if (empty($category)) {
$query = "SELECT COUNT(*) as num FROM user ";
} else {
$query = "SELECT COUNT(*) as num FROM user WHERE category = $category ";
}
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages[num];
$targetpage = "."; //your file name (the name of this file)
$limit = 1; //how many items to show per page
$page = $_GET[page];
if($page)
$start = ($page - 1) * $limit; //first item to display on this page
else
$start = 0; //if no page var is given, set start to 0
/* Get data. */
if (empty($category)) {
$sql_select = "SELECT * FROM user a, hi5 b WHERE a.id = b.ID ORDER BY a.$sortby DESC LIMIT $start, $limit ";
} else {
$sql_select = "SELECT * FROM user a, hi5 b WHERE a.id = b.ID and a.category = $category ORDER BY a.$sortby DESC LIMIT $start, $limit ";
}
//$sql_result = mysql_query($sql_select);
//while ($data = mysql_fetch_array($sql_result)) {
$result = mysql_query($sql_select);
/* Setup page vars for display. */
if ($page == 0) $page = 1; //if no page var is given, default to 1.
$prev = $page - 1; //previous page is page - 1
$next = $page + 1; //next page is page + 1
$lastpage = ceil($total_pages/$limit); //lastpage is = total pages / items per page, rounded up.
$lpm1 = $lastpage - 1; //last page minus 1
/*
Now we apply our rules and draw the pagination object.
We're actually saving the code to a variable in case we want to draw it more than once.
*/
$pnext = "page=".$prev;
$pnext .= ( isset( $category ) ) ? '&category='.$category : '';
$pnext .= ( isset( $sortby ) ) ? '&sortby='.$sortby : '';
$lpmnext = "page=".$lpm1;
$lpmnext .= ( isset( $category ) ) ? '&category='.$category : '';
$lpmnext .= ( isset( $sortby ) ) ? '&sortby='.$sortby : '';
$lnext = "page=".$lastpage;
$lnext .= ( isset( $category ) ) ? '&category='.$category : '';
$lnext .= ( isset( $sortby ) ) ? '&sortby='.$sortby : '';
$p1next = "page=1";
$p1next .= ( isset( $category ) ) ? '&category='.$category : '';
$p1next .= ( isset( $sortby ) ) ? '&sortby='.$sortby : '';
$p2next = "page=2";
$p2next .= ( isset( $category ) ) ? '&category='.$category : '';
$p2next .= ( isset( $sortby ) ) ? '&sortby='.$sortby : '';
$nnext = "page=".$next;
$nnext .= ( isset( $category ) ) ? '&category='.$category : '';
$nnext .= ( isset( $sortby ) ) ? '&sortby='.$sortby : '';
$pagination = "";
if($lastpage > 1)
{
$pagination .= "<div class=\"pagination\">";
//previous button
if ($page > 1)
$pagination.= "<a href=\"$targetpage/index.php?$pnext\" onclick=\"return loaddoc('module=sticker&$pnext')\" >« previous</a>";
else
$pagination.= "<span class=\"disabled\">« previous</span>";
//pages
if ($lastpage < 7 + ($adjacents * 2)) //not enough pages to bother breaking it up
{
for ($counter = 1; $counter <= $lastpage; $counter++)
{
$cnext = "page=".$counter;
$cnext .= ( isset( $category ) ) ? '&category='.$category : '';
$cnext .= ( isset( $sortby ) ) ? '&sortby='.$sortby : '';
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage/index.php?$cnext\" onclick=\"return loaddoc('module=sticker&$cnext')\" >$counter</a>";
}
}
else if($lastpage > 5 + ($adjacents * 2)) //enough pages to hide some
{
//close to beginning; only hide later pages
if($page < 1 + ($adjacents * 2))
{
for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
{
/*
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage/$counter\">$counter</a>";
*/
$cnext = "page=".$counter;
$cnext .= ( isset( $category ) ) ? '&category='.$category : '';
$cnext .= ( isset( $sortby ) ) ? '&sortby='.$sortby : '';
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage/index.php?$cnext\" onclick=\"return loaddoc('module=sticker&$cnext')\" >$counter</a>";
}
$pagination.= "...";
$pagination.= "<a href=\"$targetpage/index.php?$lpmnext\" onclick=\"return loaddoc('module=sticker&$lpmnext')\" >$lpm1</a>";
$pagination.= "<a href=\"$targetpage/index.php?$lnext\" onclick=\"return loaddoc('module=sticker&$lnext')\" >$lastpage</a>";
}
//in middle; hide some front and some back
else if($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
{
$pagination.= "<a href=\"$targetpage/index.php?$p1next\" onclick=\"return loaddoc('module=sticker&$p1next')\">1</a>";
$pagination.= "<a href=\"$targetpage/index.php?$p2next\" onclick=\"return loaddoc('module=sticker&$p2next')\">2</a>";
$pagination.= "...";
for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
{
/*
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage/$counter\">$counter</a>";
*/
$cnext = "page=".$counter;
$cnext .= ( isset( $category ) ) ? '&category='.$category : '';
$cnext .= ( isset( $sortby ) ) ? '&sortby='.$sortby : '';
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage/index.php?$cnext\" onclick=\"return loaddoc('module=sticker&$cnext')\" >$counter</a>";
}
$pagination.= "...";
$pagination.= "<a href=\"$targetpage/index.php?$lmpnext\" onclick=\"return loaddoc('module=sticker&$lpmnext')\">$lpm1</a>";
$pagination.= "<a href=\"$targetpage/index.php?$lnext\" onclick=\"return loaddoc('module=sticker&$lnext')\">$lastpage</a>";
}
//close to end; only hide early pages
else
{
$pagination.= "<a href=\"$targetpage/index.php?$p1next\" onclick=\"return loaddoc('module=sticker&$p1next')\">1</a>";
$pagination.= "<a href=\"$targetpage/index.php?$p2next\" onclick=\"return loaddoc('module=sticker&$p2next')\">2</a>";
$pagination.= "...";
for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
{/*
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage/$counter\">$counter</a>";
*/
$cnext = "page=".$counter;
$cnext .= ( isset( $category ) ) ? '&category='.$category : '';
$cnext .= ( isset( $sortby ) ) ? '&sortby='.$sortby : '';
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage/index.php?$cnext\" onclick=\"return loaddoc('module=sticker&$cnext')\" >$counter</a>";
}
}
}
//next button
if ($page < $counter - 1)
$pagination.= "<a href=\"$targetpage/index.php?$nnext\" onclick=\"return loaddoc('module=sticker&$nnext')\" >next »</a>";
else
$pagination.= "<span class=\"disabled\" >next »</span>";
$pagination.= "</div>
";
}
?>
<?=$pagination?>
ใช้ได้ทุกอย่างครับแต่ต้อง กด open new window อ่าครับ มันถึงไปหน้าอื่นให้
ถ้ากดปรกติมันก็จะขึ้นตัว loading แล้วก็หายไป แต่ก็อยู่หน้า เดิมครับมันไม่ไป เลยครับ
รบกวนครับ - -*
ขอบคุณครับผม
view source แล้วจะได้ เช่น
onclick="return loaddoc('module=sticker&page=2&sortby=id')"
ครับ
http://www.thaihi5list.com/ อันนี้ผมเพิ่ง upgrade ครับ จะติดเหมือนข้างต้นเรยครับ T.T