php经典分页函数_适合初学才

 更新时间:2016年11月25日 16:05  点击:1405

<?php
header("Content-type: text/html;charset=GBK");//输出编码,避免中文乱码
$page=isset($_GET['page'])?intval($_GET['page']):1;        //这句就是获取page=18中的page的值,假如不存在page,那么页数就是1。
$num=10;                                      //每页显示10条数据

$db=mysql_connect("localhost","root","7529639");           //创建数据库连接
mysql_select_db("cr_download");                 //选择要操作的数据库

/*
首先咱们要获取数据库中到底有多少数据,才能判断具体要分多少页,具体的公式就是
总数据库除以每页显示的条数,有余进一。
也就是说10/3=3.3333=4 有余数就要进一。
*/

$result=mysql_query("select * from cr_userinfo");
$total=mysql_num_rows($result); //查询所有的数据

$url='test.php';//获取本页URL

//页码计算
$pagenum=ceil($total/$num);                                    //获得总页数,也是最后一页
$page=min($pagenum,$page);//获得首页
$prepg=$page-1;//上一页
$nextpg=($page==$pagenum ? 0 : $page+1);//下一页
$offset=($page-1)*$num;                                        //获取limit的第一个参数的值,假如第一页则为(1-1)*10=0,第二页为(2-1)*10=10。

//开始分页导航条代码:
$pagenav="显示第 <B>".($total?($offset+1):0)."</B>-<B>".min($offset+10,$total)."</B> 条记录,共 $total 条记录 ";

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

$pagenav.=" <a href=javascript:dopage('result','$url?page=1');>首页</a> ";
if($prepg) $pagenav.=" <a href=javascript:dopage('result','$url?page=$prepg');>前页</a> "; else $pagenav.=" 前页 ";
if($nextpg) $pagenav.=" <a href=javascript:dopage('result','$url?page=$nextpg');>后页</a> "; else $pagenav.=" 后页 ";
$pagenav.=" <a href=javascript:dopage('result','$url?page=$pagenum');>尾页</a> ";
$pagenav.="</select> 页,共 $pagenum 页";

//假如传入的页数参数大于总页数,则显示错误信息
If($page>$pagenum){
       Echo "Error : Can Not Found The page ".$page;
       Exit;
}

$info=mysql_query("select * from cr_userinfo limit $offset,$num");   //获取相应页数所需要显示的数据
While($it=mysql_fetch_array($info)){
       Echo $it['username'];
       echo "<br>";
}                                                              //显示数据
  echo"<br>";
  echo $pagenav;//输出分页导航
  
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>php日历代码</title>
<style type="text/css">
<!--
#calendarTitle{
        width:210px;
}
#calendarMain{
        width:210px;
}
.clear{
        clear:both;
}
.titleSpan{
        width:30px;
        text-align:center;
        float:left;
}
.daySpan{
        width:30px;
        text-align:center;
        float:left;
}
-->
</style>
</head>

<body>
<div id="calendarTitle">
<div class="titleSpan">日</div>
<div class="titleSpan">一</div>
<div class="titleSpan">二</div>
<div class="titleSpan">三</div>
<div class="titleSpan">四</div>
<div class="titleSpan">五</div>
<div class="titleSpan">六</div>
<div class="clear"></div>
</div>

<div id="calendarMain">

<?
@date_default_timezone_set('+8');

function week2day($str) {
$days = array('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun');
return array_search($str, $days) + 1;
}


$selectTimestamp = time();
$curMonth = date('n', $selectTimestamp);
$curYear = date('Y', $selectTimestamp);
$curDay = week2day(date('D', $selectTimestamp));
$todayNum = date('j', $selectTimestamp);
$curMonthTotal = date('t', $selectTimestamp);
$firstDay = week2day(date('D', mktime(0,0,0,$curMonth,1,$curYear)));
$lastDay = week2day(date('D', mktime(0,0,0,$curMonth,$curMonthTotal,$curYear)));

for($i=0;$i<$firstDay;$i++){
echo('<div class="daySpan"> </div>');
}

for($i=1;$i<=$curMonthTotal;$i++){
if($i == $todayNum){
echo('<div class="daySpan">X</div>');
}else{
echo('<div class="daySpan">'.$i.'</div>');
}

}
   
?>
</div>

<div class="clear"></div>
</body>
</html>

php ajax用户注册检测代码

index.php 复制PHP内容到剪贴板 PHP代码:<tr>
              <td width="25%" class="altbg1">&nbsp;&nbsp;用 户 名<font color="red">*</font><br /></td>
              <td>
                <input size="25" name="username" type="text" value="" onBlur="startRequest(document.getElementById('username').value);" />
              </td>
              <td id="ckuser"></td>
            </tr>

 

js:ajax.js 复制PHP内容到剪贴板 var xmlHttp;
    function createXMLHttpRequest()
    {
          if(window.XMLHttpRequest)
        {
              xmlHttp = new XMLHttpRequest();//mozilla浏览器
        }
        else if(window.ActiveXObject)
        {
            try
            {
             xmlHttp = new ActiveX0bject("Msxml2.XMLHTTP");//IE老版本
            }
            catch(e)
            {}
            try
            {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");//IE新版本
            }
            catch(e)
            {}
            if(!xmlHttp)
            {
                window.alert("不能创建XMLHttpRequest对象实例");
                return false;
            }
        }
    }
   
    php ajax用户注册检测代码
    function startRequest(username)
        {
            createXMLHttpRequest();//特编
           
            xmlHttp.open("GET","ckuser.php?name="+username,true);
            xmlHttp.onreadystatechange = handleStateChange;
            xmlHttp.send(null);
        }
       
       
    function handleStateChange()
    {
        if(xmlHttp.readyState==4)
        {
            if(xmlHttp.status==200)
            {
                //alert("来自服务器的响应:" + xmlHttp.responseText);
                if(xmlHttp.responseText == "true"){
                    document.getElementById("ckuser").innerHTML = '此用户名以被人注册';
                }
                else if(xmlHttp.responseText == "false")
                {
                    document.getElementById("ckuser").innerHTML = '检测通过';
                }
            }
        }
    }

 

ckuser.php   php ajax用户注册检测代码
PHP代码:
<?php
//
    //require_once "globals.php";
    require_once "config.inc.php";
    //require_once 'common/common.php';
    $username = $_GET["name"];
   
    $con = @mysql_connect("$dbserver","$dbuser","$dbpass" )or die("无法连接到数据库!");
    mysql_query("set names gbk");
    mysql_select_db("$dbname",$con)or die("无法选择数据库!");
   
    $query="select id from hj_member where username='".$username."';";
    $res=mysql_query($query);
        if(mysql_num_rows($res)!=0)
        {
             echo "true";
        }else
            {
               echo "false";
            }


?>

<?php
 include_once ("sql_connect.php");
 include_once ("my_msg.php"); 
?>
<html>
<head>
<meta http- equiv="content-type" content="text/html" charset=utf-8 />
<title& gt;会员功能表</title> < /head> <body bgcolor = "white" text="black" link="blue" vlink="purple" alink="red">
<?php
 if(isset($_COOKIE['cookie_chk'])){
    if($_COOKIE['cookie_chk'] !="logined"){ 
       my_msg("登录失败,请重新登录!","login.php");     }
}else {       
 my_msg("登录失败,请重新登录!","login.php");     }
 ?>
<h1 align="center">欢迎<?php echo $_COOKIE['cookie_id']; ?>进入会员区<br>
  <p>会员主功能表</h1>< /p></p>
 <h3 align="center"><a href="pass.html">修改密码</a></h3>
<h3 align="center"><a href="login.php"& gt;注销</h3>
</body>
</html>

下面来看php登录

 <?php
 include_once("sql_connect.php");
include_once("my_msg.php");
?> 
<?php if($_POST['id']=='' or $_POST['passwd']==''){    
my_msg("字段不能为空!","login.php");
 }
$sqlstr ="select * from member where id='".$_POST['id']."' and passwd='".$_POST['passwd']."' and status =1";
 $result = mysql_query($sqlstr,$link);
 $row = mysql_fetch_array($result,MYSQL_BOTH);
 if(mysql_num_rows($result)==1 && $row["rank"]==100){
setcookie("cookie_chk","adm_logined");
setcookie("cookie_id",$_POST['id']);
my_header("adm.php");
 }elseif (
mysql_num_rows($result)==1 && $row["rank"]==1){
setcookie("cookie_chk","logined");
setcookie("cookie_id",$_POST['id']);
my_header("main.php");
}else {
my_msg("登录失败,请重新等录!","login.php");
 }
mysql_free_result($result);
 mysql_close($link);
?>

静态文件实现点击

<?php

require_once("a/f.php");

$id =isset($_GET['id'])?$_GET['id']:'';

if(!is_numeric($id)){

 exit('unkown');

}else{

 $sql ="update filecontent set filebrower=filebrower+1 where id=$id";

 mysql_query($sql);

 $result =mysql_query("select id,filebrower from filecontent where id=$id");

 $rs  =mysql_fetch_array($result);
}
?>
document.write('<?php echo $rs[1];?>人次');//注:这里必须以js形式出输,因我们在网页中是以<script src=./hit.php></script>

本站原创:  www.111cn.net

[!--infotagslink--]

相关文章

  • php正确禁用eval函数与误区介绍

    eval函数在php中是一个函数并不是系统组件函数,我们在php.ini中的disable_functions是无法禁止它的,因这他不是一个php_function哦。 eval()针对php安全来说具有很...2016-11-25
  • php中eval()函数操作数组的方法

    在php中eval是一个函数并且不能直接禁用了,但eval函数又相当的危险了经常会出现一些问题了,今天我们就一起来看看eval函数对数组的操作 例子, <?php $data="array...2016-11-25
  • php KindEditor文章内分页的实例方法

    我们这里介绍php与KindEditor编辑器使用时如何利用KindEditor编辑器的分页功能实现文章内容分页,KindEditor编辑器在我们点击分页时会插入代码,我们只要以它为分切符,就...2016-11-25
  • Python astype(np.float)函数使用方法解析

    这篇文章主要介绍了Python astype(np.float)函数使用方法解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...2020-06-08
  • 自己动手写的jquery分页控件(非常简单实用)

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

    这篇文章主要介绍了Python中的imread()函数用法说明,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-03-16
  • C# 中如何取绝对值函数

    本文主要介绍了C# 中取绝对值的函数。具有很好的参考价值。下面跟着小编一起来看下吧...2020-06-25
  • C#学习笔记- 随机函数Random()的用法详解

    下面小编就为大家带来一篇C#学习笔记- 随机函数Random()的用法详解。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧...2020-06-25
  • 源码分析系列之json_encode()如何转化一个对象

    这篇文章主要介绍了源码分析系列之json_encode()如何转化一个对象,对json_encode()感兴趣的同学,可以参考下...2021-04-22
  • php中去除文字内容中所有html代码

    PHP去除html、css样式、js格式的方法很多,但发现,它们基本都有一个弊端:空格往往清除不了 经过不断的研究,最终找到了一个理想的去除html包括空格css样式、js 的PHP函数。...2013-08-02
  • jquery实现的伪分页效果代码

    本文实例讲述了jquery实现的伪分页效果代码。分享给大家供大家参考,具体如下:这里介绍的jquery伪分页效果,在火狐下表现完美,IE全系列下有些问题,引入了jQuery1.7.2插件,代码里有丰富的注释,相信对学习jQuery有不小的帮助,期...2015-10-30
  • 金额阿拉伯数字转换为中文的自定义函数

    CREATE FUNCTION ChangeBigSmall (@ChangeMoney money) RETURNS VarChar(100) AS BEGIN Declare @String1 char(20) Declare @String2 char...2016-11-25
  • Android开发中findViewById()函数用法与简化

    findViewById方法在android开发中是获取页面控件的值了,有没有发现我们一个页面控件多了会反复研究写findViewById呢,下面我们一起来看它的简化方法。 Android中Fin...2016-09-20
  • C++中 Sort函数详细解析

    这篇文章主要介绍了C++中Sort函数详细解析,sort函数是algorithm库下的一个函数,sort函数是不稳定的,即大小相同的元素在排序后相对顺序可能发生改变...2022-08-18
  • PHP用strstr()函数阻止垃圾评论(通过判断a标记)

    strstr() 函数搜索一个字符串在另一个字符串中的第一次出现。该函数返回字符串的其余部分(从匹配点)。如果未找到所搜索的字符串,则返回 false。语法:strstr(string,search)参数string,必需。规定被搜索的字符串。 参数sea...2013-10-04
  • index.php怎么打开?如何打开index.php?

    index.php怎么打开?初学者可能不知道如何打开index.php,不会的同学可以参考一下本篇教程 打开编辑:右键->打开方式->经文本方式打开打开运行:首先你要有个支持运行PH...2017-07-06
  • PHP函数分享之curl方式取得数据、模拟登陆、POST数据

    废话不多说直接上代码复制代码 代码如下:/********************** curl 系列 ***********************///直接通过curl方式取得数据(包含POST、HEADER等)/* * $url: 如果非数组,则为http;如是数组,则为https * $header:...2014-06-07
  • php中的foreach函数的2种用法

    Foreach 函数(PHP4/PHP5)foreach 语法结构提供了遍历数组的简单方式。foreach 仅能够应用于数组和对象,如果尝试应用于其他数据类型的变量,或者未初始化的变量将发出错误信息。...2013-09-28
  • C语言中free函数的使用详解

    free函数是释放之前某一次malloc函数申请的空间,而且只是释放空间,并不改变指针的值。下面我们就来详细探讨下...2020-04-25
  • vue.js 表格分页ajax 异步加载数据

    Vue.js通过简洁的API提供高效的数据绑定和灵活的组件系统.这篇文章主要介绍了vue.js 表格分页ajax 异步加载数据的相关资料,需要的朋友可以参考下...2016-10-20