PHP分页方法
$pagesize=10; //设置每一页显示的记录数
$c("localhost","root",""); //连接数据库
$rs=mysql_query("select count(*) from tb_product",$conn); //取得记录总数$rs
$myrow = mysql_fetch_array($rs);
$numrows=$myrow[0];
//计算总页数
$pages=intval($numrows/$pagesize);
//判断页数设置
if (isset($_GET['page'])){
$page=intval($_GET['page']);
}
else{
$page=1; //否则,设置为第一页
}
完整代码
<?php
$c("localhost","root","");
//设定每一页显示的记录数
$pagesize=10;
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>
相关文档:
这里50个有益的PHP工具,可以大大提高你的编程工作:
调试工具
Webgrind
Xdebug
Gubed PHP Debugger
DBG
PHP_Debug
PHP_Dyn
MacGDBp
测试和优化工具
PHPUnit
SimpleTest
Selenium
PHP_CodeSniffer
dBug
PHP Profile Class
文档工具
phpDocumentor
PHP DOX
安全工具
Securimage
:验证码工具。
Scave ......
如何用php直接调用文本文件内容:首先通过file函数打开服务器上的一个文本文件,返回的$myFile 就将成为这个文件操作的句柄,然后再通过循环指令,取出文件中每一行的内容并打印出来。
编程思路
首先要使用的函数为fi1e,本函数与 readfile() 类似,不同的地方为 file 函数将文件中的内容全部读出 ......
代码interface StringSearchable
{
public function search($substring, $buffer);
}
class BoyerMooreStringSearch implements StringSearchable
{
public $substring = null;
public ......
PHP的realpath(...)
Author:zfive5(zidong)
Email :zfive5@yahoo.com.cn
引子:
昨天帮人改了一下PHP程序,在配eclipse+php(xdebug)+mysql+apache后,就陷入一步步漫长而乏味的调试中,虽然工具有些不太好用(但也对php环境9年来的进步感到兴奋), 在整个调试过程中,发现自己完全让rea ......
<p>04级新生名单</p>
<table border="1" width="80%" cellpadding="0">
<tr>
<td width="10%" align="center">Id</td>
<td width="20%" align="center">Name</td>
<td width="10%" align="center">Age</td>
<td width="10%" align="cent ......