简单实用php mysql分页代码
        来源:未知        
             时间:2014-11-27 22:50 作者:xxadmin
            阅读:次
        
        [导读] $qh =mysql_query( selectcount(*)asrcntfromtablewhereyour_condition_hereorderbywhatever ); $data =mysql_fetch_array( $qh ); $nr = $data [ rcnt ]; //判断偏移量参数是否传递给了脚本,如果没有就使用默认值0 if ( empty em...
        
                
             
            
        
            
                | 
                    
                    
	  
	
		
			
				$qh=mysql_query("select count(*) as rcnt from table where your_condition_here order by whatever");  
				$data=mysql_fetch_array($qh);  
				$nr=$data["rcnt"];  
				 
				if (emptyempty($offset)) 
				{  
				$offset=0;  
				} 
				 
				$result=mysql_query("select id,name,phone from table where your_condition_here order by whatever limit $offset, 20"); 
				 
				while ($data=mysql_fetch_array($result))  
				{ 
				 
				} 
				 
				if(!$offset)  
				{  
				$preoffset=$offset-20;  
				print "<a href="$php_self?offset=$preoffset">前一页</a>  ";  
				} 
				 
				$pages=ceil($nr/20);  
				for ($i=1; $i <= $pages; $i++)  
				{  
				$newoffset=20*$i;  
				print "<a href="$php_self?offset=$newoffset">$i</a>  ";  
				} 
				 
				if ($pages!=0 && ($newoffset/20)!=$pages)  
				{  
				print "<a href="$php_self?offset=$newoffset">下一页</a>  ";  
				}
				  |