易截截图软件、单文件、免安装、纯绿色、仅160KB

php+mysql分页


分页功能的实现是每种WEB开发语言必须要实现的功能。PHP也好,JSP也罢。我准备用两个方法来阐述PHP+MYSQL实现分页的功能。
 
一、分页程序的原理
分页程序有两个非常重要的参数:每页显示几条记录($pagesize)和当前是第几页($page)。有了这两个参数就可以很方便的写出分页程序,我们以MySql数据库作为数据源,在mysql里如果要想取出表内某段特定内容可以使用的SQL语句:select * from table limit offset,rows来实现。这里的offset是记录偏移量,它的计算方法是offset(下标意思)=$pagesize*($page-1),rows是要显示的记录条数,这里就是$page。也就是说select * from table limit 10,10这条语句的意思是取出表里从第11条记录开始的20条记录。
 
二、主要代码解析
<?php
$conn=mysql_connect("localhost","root","123");//连接数据库
$rs=mysql_query("select count(*) from tb_product",$conn); //取得记录总数$rs
$pagesize=10; //设置每一页显示的记录数
$myrow = mysql_fetch_array($rs);
$numrows=$myrow[0];
$pages=intval($numrows/$pagesize);//计算总页数
 
 
?>
 
三 完整代码
<html>
<head>
<title>php分页示例</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<?php
 $conn=mysql_connect("localhost","root","");
 //设定每一页显示的记录数
 $pagesize=1;
 mysql_select_db("mydata",$conn);
 //取得记录总数$rs,计算总页数用
 $rs=mysql_query("select count(*) from tb_product",$conn);
 $myrow = mysql_fetch_array($rs);
 $numrows=$myrow[0];
 //计算总页数
 $pages=intval($numrows/$pagesize);
 if ($numrows%$pagesize)
  $pages++;
 //设置页数
 if (isset($_GET['page'])){
  $page=intval($_GET['page']);
 }
 else{
  //设置为第一页
  $page=1;
 }
 //计算记录偏移量
 $offset=$pagesize*($page - 1);
 //读取指定记录数
 $rs=mysql_query("select * from myTable order by id desc limit $offset,$pagesize",$conn);
 if ($myrow = mysql_fetch_array($rs))
 {
  $i=0;
  ?>
  <table border="0" width="80%">
  <tr>
   <td width="50%" bgcolor="#E0E0E0">
    <p align="center">标题</td>


相关文档:

php获取原图片

<?php
/*
获取远程图片函数
*/
function GrabImage($url,$filename=""){
//若url为空返回false,无地址
if($url=="") return false;
//若$filename为空
if($filename=="") {
$ext=strrchr($url,"."); //获取"."加后缀
if($ext!=&qu ......

php mysql 配置php.ini

文件php.ini放入windows下,将下面内容拷贝到记事本命名为php.ini放入c:/windows下,重启Apache server:
[PHP]
;;;;;;;;;;;
; WARNING ;
;;;;;;;;;;;
; This is the default settings file for new PHP installations.
; By default, PHP installs itself with a configuration suitable for
; development purposes ......

php文件上传类

 
<?php
  /**
  * PHP100.com - 个人感觉非常简单,只要有点PHP基础滴人都应该能看懂~~
  * Apache2 + PHP5.0
  * Version:1.0
  * 同时感谢PHP100所有的兄弟们
  * ——————————————&m ......

CentOS apache+mysql+php安装

CENTOS 5的虚拟机,怎么从图形界面切换到命令行界面
1.临时切换:
ctrl+alt+1 …… ctrl+alt+6一共六个控制台。
2.永久关闭图形化:
在root下输入 vi /etc/inittab 将init:5修改为init:3 
Mysql rpm包安装,不能重定位(relocatable)
rpm包安装异常,--prefix 参数不能重定位,安装到另一个目录的原 ......

开始收集mysql的各种命令

  这里收集各种Mysql的基础知识,为了某些场合的需要,还是舍弃navicat之类的工具乖乖用命令行吧   
(注意有的命令需要分号有的不需要)
一.基本操作
  1.登录
     mysql -u 用户名 -p密码 数据库名
         这里需 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号