二款php mysql 分页代码

 更新时间:2016年11月25日 15:52  点击:1965
本文章提供两种mysql分页代码,分页原是都很简单就是$total = @(int)($sum / $pagesize);$p = (int)$_GET[\'page\'];再到数据库中支limti X,X就成了。
 代码如下 复制代码
function fenyezhixin($table,$pagesize="",$paixu="",$do="",$wwhere=""){
    if(($table == "news_fabu") or ($table == "product_fabu") or ($table == "message") or ($table == "down_fabu") or ($table == "kucun")){
    $query = @mysql_query("select * from $table $wwhere");
    $pagesize = $pagesize;
    $sum = mysql_num_rows($query);
    if($sum == 0){
        $pagesize = 1;
    }
 if($pagesize=="0"){
     $sum = "1";
 }
    if (@($sum % $pagesize) == 0){
     $total = @(int)($sum / $pagesize);
 }else{
     $total = @(int)($sum / $pagesize) + 1;
 }
    if($total == 0){$total=1;}
    if (isset($_get['page'])){
        $p = (int)$_get['page'];
    }else{
        $p = 1;
    }
    $start = $pagesize * ($p - 1);
    $query = @mysql_query("select * from $table $wwhere order by $paixu limit $start,$pagesize") or die ("数据查询失败2!");
    if ($do == 1){
        $queryarray = array($query,$total,$sum,$p);
        return $queryarray;
    }
    if($do == 2){
        $parray = array($total,$sum,$p);
        return $parray;
    }
 }else{
     $query = @mysql_query("select * from $table $wwhere order by $paixu limit $pagesize") or die ("数据查询失败1!");
     if ($do == 1){
            $queryarray = array($query,$total,$sum,$p);
            return $queryarray;
     }
     if($do == 2){
            $parray = array($total,$sum,$p);
            return $parray;
     }
 }
}
//返回分页条  
function fenyedaohang($total="",$sum="",$p="",$menut=""){
 $w = substr($menut,strrpos($menut,"&")+1,2);
 $wr = substr($menut,strrpos($menut,"=")+1,strlen($menut));
 $pindao = $_server["script_name"];$pinstrlen = strrpos($pindao,"/"); $pindao = substr($pindao,$pinstrlen+1,strlen($pindao));
    if($w == "pr"){
     $queryr = mysql_query("select feiye.feiye_what from feiye where feiye.feiye_page = '$pindao'");
  $rows = mysql_fetch_row($queryr); $rrows = $rows[0];
  if(empty($rrows)){
      mysql_query("insert into `feiye` (`feiye_page`, `feiye_what`) values ('$pindao', '$wr')");
   echo "<meta http-equiv='refresh' content='0'>";
  }else{
      if($wr != $rrows){
        mysql_query("update `feiye` set `feiye_what`='$wr' where (`feiye_page`='$pindao')");
     echo "<meta http-equiv='refresh' content='0'>";
   }
  }
 }
 if($w == "ne"){
     $queryr = mysql_query("select feiye.feiye_what from feiye where feiye.feiye_page = '$pindao'");
  $rows = mysql_fetch_row($queryr); $rrows = $rows[0];
  if(empty($rrows)){
      mysql_query("insert into `feiye` (`feiye_page`, `feiye_what`) values ('$pindao', '$wr')");
   echo "<meta http-equiv='refresh' content='0'>";
  }else{
      if($wr != $rrows){
        mysql_query("update `feiye` set `feiye_what`='$wr' where (`feiye_page`='$pindao')");
     echo "<meta http-equiv='refresh' content='0'>";
   } 
  }
 }
    echo "共"."$total"."页&nbsp;"."记录"."$sum"."条&nbsp;当前"."$p"."/"."$total"."页&nbsp;&nbsp;";
    if($total == 1){
        echo "<font  class="page">首页</font>";
    }else{
        echo "<a href='?page=1&menu=$menut' class="page">首页</a>"."&nbsp;";
    }
    if ($p > 1){
        $prev = $p - 1;
        echo "<a href='?page=$prev&menu=$menut' class="page">上一页</a>"."&nbsp;";
    }else{
        echo "<font class="page">上一页</font>"."&nbsp;";
    }
    $page = $_get["page"];
    $pagesum = $page+5;
    if($total >= 11){
        if($pagesum <=11 ){
            $pagesum = 11;
        }
    }
    if($pagesum >= $total){
        $pagesum = $total;
    }
    $pagestart = $page - 5;
    if($pagestart <= 0){
        $pagestart = 1;
    }
    if($total >= 11 and ($total-4) <= $page){
        $pagestart = $total-10;
    }
    for($i=$pagestart;$i<=$pagesum;$i++){
        if($i == $p){
            echo "<font color=cccccc>&nbsp;$i&nbsp;</font>";
        }else{
            echo "<a href='?page=$i&menu=$menut' class="page" >$i</a>";
        }
    }
    if ($p < $total){
        $next = $p + 1;
        echo "&nbsp;<a href='?page=$next&menu=$menut' class="page" >下一页</a>"."&nbsp;";
    }else{
        echo "<font class="page" >下一页</font>"."&nbsp;";
    }
    if($total == 1){
        echo "<font  class="page">尾页</font>";
    }else{
        echo "<a href='?page=$total&menu=$menut' class="page">尾页</a>";
    }
}
文章提供这一款简单的php 文件上传源码哦,如果你是php初学者,可以进来看看这款php 文件上传实例代码哦,好了费话不说多了进来看看这偌大文件上传代码吧。
 代码如下 复制代码

$type=filekzm($_files["filedata"]["name"]);
if ((($type == ".gif")
|| ($type == ".png")
|| ($type == ".jpeg")
|| ($type == ".jpg")
|| ($type == ".bmp"))
&& ($_files["filedata"]["size"] < 200000))
  {
  if ($_files["filedata"]["error"] > 0)
    {
    echo "返回错误: " . $_files["filedata"]["error"] . "<br />";
    }
  else
    {
    echo "上传的文件: " . $_files["filedata"]["name"] . "<br />";
    echo "文件类型: " . $type . "<br />";
    echo "文件大小: " . ($_files["filedata"]["size"] / 1024) . " kb<br />";
    echo "临时文件: " . $_files["filedata"]["tmp_name"] . "<br />";

    if (file_exists( $_files["filedata"]["name"]))
      {
      echo $_files["filedata"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_files["filedata"]["tmp_name"],
      './'.$_files["filedata"]["name"]);
      echo "stored in: " . $_files["filedata"]["name"]."<br />";
   echo "md5效验:".getget("access2008_file_md5")."<br />";
   echo "<br />上传成功!你选择的是<font color='#ff0000'>".getpost("select")."</font>--<font color='#0000ff'>".getpost("select2")."</font>";
      }
    }
  }
else
  {
  echo "上传失败,请检查文件类型和文件大小是否符合标准<br />文件类型:".$type.'<br />文件大小:'.($_files["filedata"]["size"] / 1024) . " kb";
  }
 
function filekzm($a)
{
 $c=strrchr($a,'.');
 if($c)
 {
  return $c;
 }else{
  return '';
 }
}

function getget($v)// 获取get
{
  if(isset($_get[$v]))
  {
  return $_get[$v];
  }else{
  return '';
  }
}

function getpost($v)// 获取post
{
  if(isset($_post[$v]))
  {
   return $_post[$v];
  }else{
   return '';
  }
}
?>

源码下载地址。
http://down.111cn.net/php/2010/1027/21454.html

一款超简单的php mysql 分页,也是很实例的一款函数,他可以自动获取用户增加的参数,而不需要用户来增加,很自能化的一款自能分页程序。

+-----------------------------------------------------------------------
| 文件概要:分页显示函数
| 文件名称:page.php
| 创建时间:2010-5-20
+-----------------------------------------------------------------------
*/
 function _pageft($totle, $displaypg = 20, $url = '') {

  global $page, $firstcount, $pagenav, $_server;

  $globals["displaypg"] = $displaypg;

  if (!$page)
   $page = 1;
  if (!$url) {
   $url = $_server["request_uri"];
  }

  //url分析:
  $parse_url = parse_url($url);
  $url_query = $parse_url["query"]; //单独取出url的查询字串
  if ($url_query) {
   $url_query = preg_replace("/(^|&)page=$page/", "", $url_query);
   $url = str_replace($parse_url["query"], $url_query, $url);
   if ($url_query)
    $url .= "&page";
   else
    $url .= "page";
  } else {
   $url .= "?page";
  }
  $lastpg = ceil($totle / $displaypg); //最后页,也是总页数
  $page = min($lastpg, $page);
  $prepg = $page -1; //上一页
  $nextpg = ($page == $lastpg ? 0 : $page +1); //下一页
  $firstcount = ($page -1) * $displaypg;

  //开始分页导航条代码:
  $pagenav = "显示第 <b>" . ($totle ? ($firstcount +1) : 0) . "</b>-<b>" . min($firstcount + $displaypg, $totle) . "</b> 条记录&nbsp;&nbsp;共 <font color='red'>$totle</font> 条留言";

  //如果只有一页则跳出函数:
  if ($lastpg <= 1)
   return false;

  $pagenav .= " <a href='$url=1'>首页</a> ";
  if ($prepg)
   $pagenav .= " <a href='$url=$prepg'>前页</a> ";
  else
   $pagenav .= " 前页 ";
  if ($nextpg)
   $pagenav .= " <a href='$url=$nextpg'>后页</a> ";
  else
   $pagenav .= " 后页 ";
  $pagenav .= " <a href='$url=$lastpg'>尾页</a> ";

  //下拉跳转列表,循环列出所有页码:
  $pagenav .= " 到第 <select class='border:1px solid #98ccfa;' name='topage' size='1' onchange='window.location="$url="+this.value'>n";
  for ($i = 1; $i <= $lastpg; $i++) {
   if ($i == $page)
    $pagenav .= "<option value='$i' selected>$i</option>n";
   else
    $pagenav .= "<option value='$i'>$i</option>n";
  }
  $pagenav .= "</select> 页&nbsp;&nbsp;&nbsp;共 <font color='red'>$lastpg</font> 页";
 }
?>

 在php中有很多方法来把目录所有文件列出的代码,用e
*/

$list = scandir(".");
    $zipname = "";
    foreach($list as $file)
    {
      if($file=="."||$file=="..")continue;
      $b=substr($file,-3);
      if($b==".gz"||$b==".fz")
      { $zipname = $file; break; }
    }
 
//代码二

$d=dir(".");
echo $d->path.$e;
while(false !== ($e= $d->read())) {
    echo "<a href=$e target=_blank >$e</a>"."<br>";
    }
$d->close();


//最简单的方法

$dirs    = array();
foreach(glob("test/*") as $d)
{
    if(is_dir($d))
    {
        $dirs[]    = $d;
    }
}
print_r($dirs);

//方法四

glob("test/*", glob_onlydir) ;

//方法五

function clean_dir($path)        {
        if (!is_dir($path))        {
                if (is_file($path))        {
                        unlink($path);
                }
                return;
        }
        $p=opendir($path);
        while ($f=readdir($p))        {
                if ($f=="." || $f=="..") continue;
                clean_dir($path.$f);
        }
        rmdir($path);
        return;
}

本文章提供一款完整的php目录 文件在线解压缩程序,他可打包指定目录并且把目录下所有目录与文件名都打包好,按rar的方式打包,目录结构不变,同时也提供解压功能。

$fz = new fmzip;
$fz->setzipname("打包文件名");

#打包/压缩
$fz->setsource("待打包目录");
$fz->compress($silent,$compress);

#解包/解压
$fz->settarget("待解包目录");
$fz->uncompress($silent);
*/
class fmzip
{

var $source; //压缩源
var $target; //解压目的文件夹
var $zipname;//压缩文件名
var $handle; //打开压缩文件的句柄
var $silent; //是否输出
var $count_dir; //计数器_文件夹
var $count_file;//计数器_文件
var $dirlist;

function setsource($source)//设置压缩源
{
  if(!file_exists($source))
    die("source <$source> does not exist.");
  $this->source = $source;
}

function settarget($target)//设置解压目的文件夹
{
  if(!file_exists($target))
    $this->makedir($target);
  chdir(dirname($_server['script_filename']));
  if(substr($target,-1)=="/")
    $target = substr($target,0,strlen($target)-1);
  if(!file_exists($target))
  {
    die("target <$target> does not exist.");
  }
  $this->target = $target;
}

function setzipname($zipname)//设置压缩文件名
{
  if(empty($zipname)) $zipname = "fmzip.fz";
  $this->zipname = $zipname;
}

function compress($silent = false, $compress = true) //压缩
{
  $this->silent = $silent;
  if($silent===false)echo "<pre>compressing...rn";
  if(is_file("$this->zipname"))unlink("$this->zipname");
  $this->handle = fopen($this->zipname,"w");//创建压缩文件
  if($this->handle == null) die("error creating $this->zipname");//打开失败
  $this->count_dir = 0; $this->count_file = 0; //初始化计数器
  $this->merge($this->source);//压缩
  fwrite($this->handle,"-1");//结束标志
  fclose($this->handle);//关闭文件
  echo "rndirectory: $this->count_dir";
  echo "rnfile: $this->count_filern";
  if(function_exists("gzcompress") && $compress==true)
  {
    file_put_contents("$this->zipname.gz",gzcompress(file_get_contents("$this->zipname")));
    unlink("$this->zipname");
  }
  if($silent===false)
  {
    echo $this->listfile();
    echo "</pre>";
  }
}

function listfile()
{
  if(file_exists("$this->zipname.gz"))
    return "<a href="$this->zipname.gz" target="_blank">download $this->zipname.gz</a>";
  if(file_exists("$this->zipname"))
    return "<a href="$this->zipname" target="_blank">download $this->zipname</a>";
}

function merge($dir)//合并文件、文件夹(递归)
{
/* 说明:不处理link。 */
 if(is_dir($dir))//如果压缩源是文件夹
 {
  $list = scandir($dir);//扫描文件列表
  natcasesort($list);
  foreach($list as $file)//先处理文件夹
  {
    $full = "$dir/$file";
    if(!is_dir($full)||$file=="."||$file=="..")continue;//只处理文件夹
    $this->count_dir++;
    if($this->silent===false)
      echo "[dir] $fullrn"; //输出提示
    fwrite($this->handle,$this->file_info($full));//写入文件夹信息
    $this->merge($full);//递归合并下级文件夹
  }//文件夹处理完毕;
  foreach($list as $file)//处理文件
  {
    $full = "$dir/$file";
    if(!is_file($full)||$file=="."||$file=="..")continue; //只处理文件
    $this->count_file++;
    if($this->silent===false)
      echo "[file] $fullrn";//输出提示
    fwrite($this->handle,$this->file_info($full));//写入文件信息
  }//文件处理完毕
 }
 else
 {
   $this->count_file++;
   if($this->silent===false)echo "[file] $fullrn";//输出提示
   fwrite($this->handle,$this->file_info($file));//写入文件信息
 }
}//end function merge

function file_info($file)
{
  $perm = substr(sprintf('%o',fileperms($file)), -3); //权限
  $filename = str_replace($this->source,"",$file);
  if(is_file($file))//文件
  {
    $size = filesize($file); //文件大小
    return "1rn$filenamern$permrn$sizern".file_get_contents($file)."rn";// .文件内容
  }
  if(is_dir($file))//目录
    return "0rn$filenamern$permrn";
}//end function file_info

function uncompress($silent = false)
{
  $this->silent = $silent;
  if($silent===false)echo "<pre>uncompressing...rn";
  if(substr($this->zipname,-3)==".gz")
    $this->zipname = substr($this->zipname,0,strlen($this->zipname)-3);
  if(file_exists("$this->zipname.gz"))
  {
    if(!function_exists(gzuncompress))
      die("function gzuncompress is not supported. unable to continue.");
    file_put_contents($this->zipname,gzuncompress(file_get_contents("$this->zipname.gz")));
  }
  $this->handle = fopen($this->zipname,"r");
  if($this->handle == null) die("error reading $this->zipname");//打开失败
  $count = 0;
  while(1)
  {
    $count ++;
    $type = $this->read_line(); //读取类型
    if($type === "-1")break;//处理完毕,退出
    $filename = $this->target.$this->read_line();//读取文件名
    $permission = $this->read_line();//读取权限
/* <文件夹> [0]n[file_name]n[perm]n */
    if($type === "0")//目录
    {
      if($this->silent === false)//输出提示
        echo "[dir] $filename  [$permission]rn";
      $this->makedir($filename);//创建文件夹
      chdir(dirname($_server['script_filename']));
      chmod($filename,$permission);
      $this->dirlist[$filename] = 1;
      continue;
    }
/* <文件> [1]n[file_name]n[perm]n[size]n[contents]n */
    if($type === "1")//文件
    {
      $this->count_file++;
      $size = $this->read_line(); //读取文件大小
      if($this->silent === false)//输出提示
        echo "[file] $filename  [$permission] [size = $size]rn";
      if($size!=0)
      {
        $fp = fopen($filename,"w");
        $contents = fread($this->handle,$size);
        fwrite($fp,$contents);
        fclose($fp);
        chmod($filename,$permission);
      }
      $this->read_line();//内容后的一个回车
      continue;
    }
  }
  $this->count_dir = count($this->dirlist);
  if($silent===false)
    echo "ndirectory: $this->count_dir";
    echo "nfile: $this->count_filen</pre>n";
  fclose($this->handle);
  if(file_exists("$this->zipname.gz"))unlink("$this->zipname");
}//end function uncompress;

function read_line()
{
  $a = fgets($this->handle);
  $a = str_replace("rn","",$a);
  $a = str_replace("n","",$a);
  return $a;
}

function makedir($full)
{
  list($a,$b) = split("/",$full,2);
  if($a == "") return;
  if(file_exists($a)&&!is_dir($a))die("can't create dir $a");
  if(!file_exists($a))@mkdir($a);
  chdir($a);
  if($b!=="")
    $this->makedir($b);
  chdir("..");
}//end function makedir

} //end class fmzip

/*

使用方法:

#必须
include("包含这个class的php文件");
$fz = new fmzip;
$fz->setzipname("打包文件名");

#打包/压缩
$fz->setsource("待打包目录");
$fz->compress($silent,$compress);

#解包/解压
$fz->settarget("待解包目录");
$fz->uncompress($silent);

$silent : true|false (不加引号!) 是否产生输出 默认为true,不产生
$compress : true|false (不加引号!) 是否压缩 默认为true,压缩

[!--infotagslink--]

相关文章

  • php KindEditor文章内分页的实例方法

    我们这里介绍php与KindEditor编辑器使用时如何利用KindEditor编辑器的分页功能实现文章内容分页,KindEditor编辑器在我们点击分页时会插入代码,我们只要以它为分切符,就...2016-11-25
  • MySQL性能监控软件Nagios的安装及配置教程

    这篇文章主要介绍了MySQL性能监控软件Nagios的安装及配置教程,这里以CentOS操作系统为环境进行演示,需要的朋友可以参考下...2015-12-14
  • 自己动手写的jquery分页控件(非常简单实用)

    最近接了一个项目,其中有需求要用到jquery分页控件,上网也找到了需要分页控件,各种写法各种用法,都是很复杂,最终决定自己动手写一个jquery分页控件,全当是练练手了。写的不好,还请见谅,本分页控件在chrome测试过,其他的兼容性...2015-10-30
  • 不打开网页直接查看网站的源代码

      有一种方法,可以不打开网站而直接查看到这个网站的源代码..   这样可以有效地防止误入恶意网站...   在浏览器地址栏输入:   view-source:http://...2016-09-20
  • 详解Mysql中的JSON系列操作函数

    新版 Mysql 中加入了对 JSON Document 的支持,可以创建 JSON 类型的字段,并有一套函数支持对JSON的查询、修改等操作,下面就实际体验一下...2016-08-23
  • php 调用goolge地图代码

    <?php require('path.inc.php'); header('content-Type: text/html; charset=utf-8'); $borough_id = intval($_GET['id']); if(!$borough_id){ echo ' ...2016-11-25
  • JS基于Mootools实现的个性菜单效果代码

    本文实例讲述了JS基于Mootools实现的个性菜单效果代码。分享给大家供大家参考,具体如下:这里演示基于Mootools做的带动画的垂直型菜单,是一个初学者写的,用来学习Mootools的使用有帮助,下载时请注意要将外部引用的mootools...2015-10-23
  • JS+CSS实现分类动态选择及移动功能效果代码

    本文实例讲述了JS+CSS实现分类动态选择及移动功能效果代码。分享给大家供大家参考,具体如下:这是一个类似选项卡功能的选择插件,与普通的TAb区别是加入了动画效果,多用于商品类网站,用作商品分类功能,不过其它网站也可以用,...2015-10-21
  • JS实现自定义简单网页软键盘效果代码

    本文实例讲述了JS实现自定义简单网页软键盘效果。分享给大家供大家参考,具体如下:这是一款自定义的简单点的网页软键盘,没有使用任何控件,仅是为了练习JavaScript编写水平,安全性方面没有过多考虑,有顾虑的可以不用,目的是学...2015-11-08
  • jquery实现的伪分页效果代码

    本文实例讲述了jquery实现的伪分页效果代码。分享给大家供大家参考,具体如下:这里介绍的jquery伪分页效果,在火狐下表现完美,IE全系列下有些问题,引入了jQuery1.7.2插件,代码里有丰富的注释,相信对学习jQuery有不小的帮助,期...2015-10-30
  • php 取除连续空格与换行代码

    php 取除连续空格与换行代码,这些我们都用到str_replace与正则函数 第一种: $content=str_replace("n","",$content); echo $content; 第二种: $content=preg_replac...2016-11-25
  • php简单用户登陆程序代码

    php简单用户登陆程序代码 这些教程很对初学者来讲是很有用的哦,这款就下面这一点点代码了哦。 <center> <p>&nbsp;</p> <p>&nbsp;</p> <form name="form1...2016-11-25
  • 深入研究mysql中的varchar和limit(容易被忽略的知识)

    为什么标题要起这个名字呢?commen sence指的是那些大家都应该知道的事情,但往往大家又会会略这些东西,或者对这些东西一知半解,今天我总结下自己在mysql中遇到的一些commen sense类型的问题。 ...2015-03-15
  • PHP实现清除wordpress里恶意代码

    公司一些wordpress网站由于下载的插件存在恶意代码,导致整个服务器所有网站PHP文件都存在恶意代码,就写了个简单的脚本清除。恶意代码示例...2015-10-23
  • MySQL 字符串拆分操作(含分隔符的字符串截取)

    这篇文章主要介绍了MySQL 字符串拆分操作(含分隔符的字符串截取),具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-02-22
  • JS实现双击屏幕滚动效果代码

    本文实例讲述了JS实现双击屏幕滚动效果代码。分享给大家供大家参考,具体如下:这里演示双击滚屏效果代码的实现方法,不知道有觉得有用处的没,现在网上还有很多还在用这个特效的呢,代码分享给大家吧。运行效果截图如下:在线演...2015-10-30
  • js识别uc浏览器的代码

    其实挺简单的就是if(navigator.userAgent.indexOf('UCBrowser') > -1) {alert("uc浏览器");}else{//不是uc浏览器执行的操作}如果想测试某个浏览器的特征可以通过如下方法获取JS获取浏览器信息 浏览器代码名称:navigator...2015-11-08
  • mysql的3种分表方案

    一、先说一下为什么要分表:当一张的数据达到几百万时,你查询一次所花的时间会变多,如果有联合查询的话,有可能会死在那儿了。分表的目的就在于此,减小数据库的负担,缩短查询时间。根据个人经验,mysql执行一个sql的过程如下:1...2014-05-31
  • JS日期加减,日期运算代码

    一、日期减去天数等于第二个日期function cc(dd,dadd){//可以加上错误处理var a = new Date(dd)a = a.valueOf()a = a - dadd * 24 * 60 * 60 * 1000a = new Date(a)alert(a.getFullYear() + "年" + (a.getMonth() +...2015-11-08
  • PHP开发微信支付的代码分享

    微信支付,即便交了保证金,你还是处理测试阶段,不能正式发布。必须到你通过程序测试提交订单、发货通知等数据到微信的系统中,才能申请发布。然后,因为在微信中是通过JS方式调用API,必须在微信后台设置支付授权目录,而且要到...2014-05-31