เกี่ยวกับแบ่งหน้า ด้วย php เพิ่ม หัว ท้าย ด้วย thead และ tfoot อย่างง่าย

ถาม-ตอบ แนะนำไอเดียว โค้ดตัวอย่าง แนวทาง วิธีแก้ปัญหา เกี่ยวกับแบ่งหน้า ด้วย php เพิ่ม หัว ท้าย ด้วย thead และ tfoot อย่างง่าย

เกี่ยวกับแบ่งหน้า ด้วย php เพิ่ม หัว ท้าย ด้วย thead และ tfoot อย่างง่าย
พอผมลองเปลี่ยนตัว SQL โดยเพิ่ม where cat_id=5 ลงไป ข้อมูลมันก็เพี้ยนๆ หมดเลยครับ ไม่ทราบว่าจะแก้ตรงไหนดีครับ


Pusirinon 115.87.220.xxx 07-04-2014 13:46:01

คำแนะนำ และการใช้งาน

สมาชิก กรุณา ล็อกอินเข้าระบบ เพื่อตั้งคำถามใหม่ หรือ ตอบคำถาม สมาชิกใหม่ สมัครสมาชิกได้ที่ สมัครสมาชิก


  • ถาม-ตอบ กรุณา ล็อกอินเข้าระบบ
  • เปลี่ยน


    ( หรือ เข้าใช้งานผ่าน Social Login )

 ความคิดเห็นที่ 1
ถ้าเปลี่ยนเฉพาะตรงนั้น ไม่น่ามีปัญหาน่ะ

เป็นกับข้อมูลหรือเปล่า อันนี้คงต้องไล่ดู

หรือไม่ลองแทรกโค้ดมาดูก็ได้ครับ


ninenik 58.11.139.xxx 07-04-2014
 ความคิดเห็นที่ 2
หรือลองใช้โค้ดตัวนี้แทนก็ได้ครับ

มีการปรับเพิ่มเติม จากหัวข้อก่อนหน้า

แนวทาง การค้นหาข้อมูล และแบ่งหน้า ด้วย php 


ninenik 58.11.139.xxx 07-04-2014
 ความคิดเห็นที่ 3
ผมลองใช้ code ตามที่พี่มีตัวอย่างให้เลยครับ ขอบคุณครับ

<?php include ('config.php') ?>
<?php include ('changeDate.php') ?>
<?php
// ฟังก์ชั่นสำหรับการแบ่งหน้า NEW MODIFY
function page_navi($before_p,$plus_p,$total,$total_p,$chk_page){      
    global $urlquery_str;   
    $pPrev=$chk_page-1;   
    $pPrev=($pPrev>=0)?$pPrev:0;   
    $pNext=$chk_page+1;   
    $pNext=($pNext>=$total_p)?$total_p-1:$pNext;        
    $lt_page=$total_p-4;   
    if($chk_page>0){     
        echo "<a  href='$urlquery_str"."pages=".intval($pPrev+1)."' class='naviPN'>Prev</a>";   
    }   
    if($total_p>=11){   
        if($chk_page>=4){   
            echo "<a $nClass href='$urlquery_str"."pages=1'>1</a><a class='SpaceC'>. . .</a>";      
        }   
        if($chk_page<4){   
            for($i=0;$i<$total_p;$i++){     
                $nClass=($chk_page==$i)?"class='selectPage'":"";   
                if($i<=4){   
                echo "<a $nClass href='$urlquery_str"."pages=".intval($i+1)."'>".intval($i+1)."</a> ";      
                }   
                if($i==$total_p-1 ){    
                echo "<a class='SpaceC'>. . .</a><a $nClass href='$urlquery_str"."pages=".intval($i+1)."'>".intval($i+1)."</a> ";      
                }          
            }   
        }   
        if($chk_page>=4 && $chk_page<$lt_page){   
            $st_page=$chk_page-3;   
            for($i=1;$i<=5;$i++){   
                $nClass=($chk_page==($st_page+$i))?"class='selectPage'":"";   
                echo "<a $nClass href='$urlquery_str"."pages=".intval($st_page+$i+1)."'>".intval($st_page+$i+1)."</a> ";         
            }   
            for($i=0;$i<$total_p;$i++){     
                if($i==$total_p-1 ){    
                $nClass=($chk_page==$i)?"class='selectPage'":"";   
                echo "<a class='SpaceC'>. . .</a><a $nClass href='$urlquery_str"."pages=".intval($i+1)."'>".intval($i+1)."</a> ";      
                }          
            }                                      
        }      
        if($chk_page>=$lt_page){   
            for($i=0;$i<=4;$i++){   
                $nClass=($chk_page==($lt_page+$i-1))?"class='selectPage'":"";   
                echo "<a $nClass href='$urlquery_str"."pages=".intval($lt_page+$i)."'>".intval($lt_page+$i)."</a> ";      
            }   
        }           
    }else{   
        for($i=0;$i<$total_p;$i++){     
            $nClass=($chk_page==$i)?"class='selectPage'":"";   
            echo "<a href='$urlquery_str"."pages=".intval($i+1)."' $nClass  >".intval($i+1)."</a> ";      
        }          
    }      
    if($chk_page<$total_p-1){   
        echo "<a href='$urlquery_str"."pages=".intval($pNext+1)."'  class='naviPN'>Next</a>";   
    }   
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" class="background-main no-js">

<head>
    <title>7Innovation Awards</title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<link href="images/favicon.gif" rel="shortcut icon"/>
    <link href="framework/addons/camera/css/camera.css" rel="stylesheet" />

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <script src="framework/js/html5shiv.js"></script>
        <script src="framework/js/respond.min.js"></script>
    <![endif]-->

    <link href="social-icons.css" rel="stylesheet" />

    <link href="style.css" rel="stylesheet" />

    <link href="theme-color.css" rel="stylesheet" />

    <link href="responsive.css" rel="stylesheet" />

	<link href="firefox.css" rel="stylesheet" />

    <script src="framework/js/modernizr.js"></script>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script type="text/javascript" src="fancybox2/jquery.fancybox-1.3.4.pack.js"></script>
<link rel="stylesheet" type="text/css" href="fancybox2/jquery.fancybox-1.3.4.css" media="screen" />
<script type="text/javascript" src="fancybox2/video.js"></script>

<style type="text/css">
/* css แบ่งหน้า */
.browse_page{   
    clear:both;   
    margin-left:12px;   
    height:25px;   
    margin-top:5px;   
    display:block;   
}   
.browse_page a,.browse_page a:hover{   
    display:block;   
    height:25px;    
    width:45px;   
    font-size:14px;   
    float:left;   
    margin:0px 5px;
    border:1px solid #CCCCCC;   
    background-color:#F4F4F4;   
    color:#333333;   
    text-align:center;   
    line-height:22px;   
    font-weight:bold;   
    text-decoration:none;   
	-webkit-border-radius: 10px;
	-moz-border-radius: 10px;
	border-radius: 10px;	
}   
.browse_page a:hover{   
	border:1px solid #CCCCCC;
	background-color:#FEB500;
    color:#FFFFFF;   
}   
.browse_page a.selectPage{   
    display:block;   
    height:25px;   
    width:45px;   
    font-size:14px;   
    float:left;   
    margin-right:2px;   
	border:1px solid #CCCCCC;
	background-color:#FEB500;
    color:#FFFFFF;   
    text-align:center;   
    line-height:22px;    
    font-weight:bold;   
	-webkit-border-radius: 10px;
	-moz-border-radius: 10px;
	border-radius: 10px;	
}   
.browse_page a.SpaceC{   
    display:block;   
    height:25px;   
    width:45px;   
    font-size:14px;   
    float:left;   
    margin-right:2px;   
    border:0px dotted #0A85CB;   
    background-color:#FFFFFF;   
    color:#333333;   
    text-align:center;   
    line-height:22px;   
    font-weight:bold;   
	-webkit-border-radius: 10px;
	-moz-border-radius: 10px;
	border-radius: 10px;	
}   
.browse_page a.naviPN{   
    width:50px;   
    font-size:12px;   
	height:25px;  
    display:block;   
/*    width:25px;   */
    float:left;   
	border:1px solid #CCCCCC;
	background-color:#FEB500;
    color:#FFFFFF;   
    text-align:center;   
    line-height:22px;   
    font-weight:bold;      
	-webkit-border-radius: 10px;
	-moz-border-radius: 10px;
	border-radius: 10px;	
}  
/* จบ css แบ่งหน้า */
</style>
</head>

<body>

    <!-- Main Container -->
    <div class="container main-site-container sb-none-layout" itemscope itemtype="http://schema.org/CreativeWork">
        <div class="row">
            <div class="col-md-12">

                <!-- main content -->
                <article class="article-container" itemscope itemtype="http://schema.org/Article">

                    <div class="article-content timeline-page">
                        <header>

                            <h1 itemprop="headline">Timeline Page</h1>

                            <div class="divider"></div>
                        </header>

                        <div class="post-entry" itemprop="articleBody">
                        </div>

                        <div class="items">

                            <ul class="cbp_tmtimeline">
<?php
        $i=1;
        $q="SELECT * FROM form_tb where cat_id=5";
        $qr=@mysql_query($q);	
		
		$total=@mysql_num_rows($qr);
		$e_page=3; // กำหนด จำนวนรายการที่แสดงในแต่ละหน้า   
		if(!isset($_GET['pages'])){   
			$_GET['pages']=0;   
		}else{   
			$_GET['pages']=$_GET['pages']-1;
			if($_GET['pages']<0){
				$_GET['pages']=0;	
			}
			$chk_page=$_GET['pages'];     
			$_GET['pages']=$_GET['pages']*$e_page;   
		}   
		$q.=" ORDER BY id DESC  LIMIT ".$_GET['pages'].",$e_page";
			
		$qr=@mysql_query($q);	
		if(@mysql_num_rows($qr)>=1){   
			$plus_p=($chk_page*$e_page)+@mysql_num_rows($qr);   
		}else{   
			$plus_p=($chk_page*$e_page);       
		}   
		$total_p=ceil($total/$e_page);   
		$before_p=($chk_page*$e_page)+1;  
		/// END PAGE NAVI ZONE			
		
        while($rs=@mysql_fetch_array($qr)){
?>  
								<li class="post-item" data-showonscroll="true" data-animation="fadeIn">
                                    <time class="cbp_tmtime"><span><? $today=strtotime($rs['date']); print substr(thai_date($today),0,18); ?></span><span><? $today=strtotime($rs['date']); print substr(thai_date($today),18,11); ?></span></time>
                                    <div class="cbp_tmicon">
                                        <i class="icon-location"></i>
                                    </div>
                                    <div class="cbp_tmlabel">
                                        <h2><?=$rs['name']?></h2>
                                        <p><?print mb_substr(strip_tags($rs['detail']),0,500,'UTF-8'); ?>...</p>
										<br/>
                                                <div class="post-meta-extended clearfix">
                                                    <span class="read-more"><i class="icon-eye3"></i><a href="show_detail.php?id=<?print "$rs[id]";?>">Read More...</a></span>
                                                </div>
									</div>
                                </li>
<?php $i++; } ?>
<div style="margin:auto;width:95%;">
    <?php if($total>10){ ?>                  
    <div class="browse_page">   
    <?php      
    if(count($_GET)<=1){
        $urlquery_str="?";
    }else{
		$para_get="";
		foreach($_GET as $key=>$value){
			if($key!="pages"){
				$para_get.=$key."=".$value."&";
			}
		}
        $urlquery_str="?$para_get";
    }
    // เรียกใช้งานฟังก์ชั่น สำหรับแสดงการแบ่งหน้า      
    ?>
    </div>   
    <?php } ?>     
                            </ul>
							<br/>
                            <footer class="blog-pagination">
                                <ul class="pagination">
                                    <li>
										<div style="margin:auto;width:100%;">
										<?php if($total>10){ ?>                  
										<div class="browse_page">   
										<?php      
										// เรียกใช้งานฟังก์ชั่น สำหรับแสดงการแบ่งหน้า      
										page_navi($before_p,$plus_p,$total,$total_p,$chk_page);       
										?>
										</div>   
										<?php } ?>     
										</div>
									</li>
                                </ul>
                            </footer>

                        </div>

                    </div>
                </article>

         </div>
       </div>

    </div>

</body>
</html>


pusirinon 58.11.87.xxx 07-04-2014 15:55
 ความคิดเห็นที่ 4
แต่ถ้าแค่ select * from form_tb ออกจากมาอย่างจะไม่มีปัญหานะครับ


pusirinon 58.11.87.xxx 07-04-2014 16:10
 ความคิดเห็นที่ 5
น่าจะเป็นตรงเนื้อหา ที่มาแสดง

mb_substr(strip_tags($rs['detail']

ลองตัดตรงนี้ดู

หรือไล่ตัดทีละตัว ว่าตัวไหนมีผล 


ninenik 58.11.139.xxx 07-04-2014
 ความคิดเห็นที่ 6
ผมลองไล่ดูหมดแล้วครับ และลองเปลี่ยนทีละตัวแบบที่พี่แนะนำ

ผลคือ ถ้าไม่ใส่ where cat_id

ข้อมูลจะออกมาทั้งตาราง และแบ่งหน้าให้เรียบร้อย


ในที่นี้ผมกำหนดตัว $e_page=3; // กำหนด จำนวนรายการที่แสดงในแต่ละหน้า   
 
แต่ใส่ตัว where cat_id เข้าไปจะโชว์ข้อมูลของ cat_id ออกมา 3 ตัว

โดยไม่แบ่งหน้าให้ครับ

ขอบคุณครับ


pusirinon 58.11.87.xxx 07-04-2014 16:38
 ความคิดเห็นที่ 7

<?php if($total>10){ ?>   

อาจจะต้องแก้ตรงนี้ด้วยไหม

ถ้ากำหนดเท่ากับ 3 ตรงนี้เปลี่ยนให้เป็น 3 ด้วย 

เพราะอันนี้กำหนด ข้อมูลให้มาก 10 ถึงจะแสดง





ninenik 58.11.139.xxx 07-04-2014
 ความคิดเห็นที่ 8
ขอบคุณพี่นิกมากๆ นะครับ ได้แล้วครับ


pusirinon 58.11.87.xxx 07-04-2014 16:59
1






เว็บไซต์ของเราให้บริการเนื้อหาบทความสำหรับนักพัฒนา โดยพึ่งพารายได้เล็กน้อยจากการแสดงโฆษณา โปรดสนับสนุนเว็บไซต์ของเราด้วยการปิดการใช้งานตัวปิดกั้นโฆษณา (Disable Ads Blocker) ขอบคุณครับ