|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
如果你单纯是为了做网站赚钱,我想你还是别学php的好,去学ASP,JSP好了,毕竟它们有实力雄厚的公司去支持它们。mysql|分页 class RSPage {
var $Debug = 0;
var $sqoe = 1; // sqoe= show query on error
var $Link_ID = 0;
var $Record = array();
var $Row;
var $numRow;
var $Parse;
var $Error = "";
var $m_timeFmt = "YYYY-MM-DD HH24:MI:SS";
var $m_num=-1;
var $m_sql;
var $m_pageSize=10;
var $m_cmt;
var $m_curPage=1;
function open($DB_Link)
{
$this->Link_ID = $DB_Link;
}
function query($Query_String,$page=1,$cnt=-1,$size=10) {
if($Query_String=="")
{
echo "履行语句不克不及为空!";
return false;
}
if(!$page)
$page = 1;
if(!$cnt)
$cnt = -1;
$this->m_pageSize = $size;
if($this->Parse){
mysql_free_result($this->Parse);
}
if($cnt!=-1){
$this->m_num = $cnt;
}
else{
$result = mysql_query($Query_String, $this->Link_ID);
if(!$result){
$this->Error=mysql_error($this->Link_ID);
}
else{
$this->m_num = mysql_num_rows($result);
}
/*
$cntsql = "select count(*) max_num from ($Query_String)";
$maxnum = 0;
$result = mysql_query($sqlstr,$this->Link_ID);
$ret = mysql_fetch_array($result);
mysql_free_result($result);
if(!$ret) {
$this->Error=mysql_error($this->Link_ID);
}
else {
$this->m_num = $ret["max_num"];
}
*/
}
$pageCount = $this->getPageCount();
$pageSize = $this->getPageSize();
if($page>$pageCount)$page=$pageCount;
if($page<1)$page=1;
$this->m_curPage=$page;
$posBegin = ($page-1)*$pageSize;
$posEnd = $posBegin + $pageSize;
$Query_String = "$Query_String LIMIT $posBegin,$posEnd";
$this->Parse=mysql_query($Query_String,$this->Link_ID);
if(!$this->Parse) {
$this->Error=mysql_error($this->Link_ID);
}
$this->Row=0;
if($this->Debug) {
printf("Debug: query = %s<br>\n", $Query_String);
}
if ($this->Error && $this->sqoe)
echo "<BR><FONT color=red><B>".$this->Error["message"]."<BR>Query :\"$Query_String\"</B></FONT>";
$numRow=mysql_num_rows($this->Parse);
return $this->Parse;
}
function setTimeFormat($timestr){
$this->m_timeFmt = $timestr;
}
function next_record() {
if(!($row = mysql_fetch_array($this->Parse))) {
mysql_free_result($this->Parse);
$this->Parse = false;
$stat=0;
}
else {
while(list($key,$val)=each($row)) {
$colreturn=strtolower($key);
$this->Record[ "$colreturn" ] = $val;
if($this->Debug) echo"<b>[$key]</b>:".$val."<br>\n";
}
$stat=1;
}
return $stat;
}
function record_exist() {
if(0 == mysql_num_rows($this->Parse)) {
return 0;
} else {
return 1;
}
return $stat;
}
function seek($pos) {
$this->Row=$pos;
}
function affected_rows() {
return mysql_affected_rows($this->Parse);
}
function num_rows() {
return mysql_num_rows($this->Parse);
}
function f($Name) {
return $this->Record[$Name];
}
function p($Name) {
print $this->Record[$Name];
}
function close() {
if($this->Debug) {
//printf("Disconnecting...<br>\n");
}
if($this->Parse){
mysql_free_result($this->Parse);
}
//mysql_close($this->Link_ID);
}
//---public 失掉以后页
function getCurPage(){return $this->m_curPage;}
//---public 设定页长
function setPageSize($page_size){$this->m_pageSize = $page_size;}
//---public 失掉页长
function getPageSize(){return $this->m_pageSize;}
//---public 失掉记载总数
function getCount(){return $this->m_num;}
//---public 失掉页总数
function getPageCount(){
$page=floor($this->getCount()/$this->getPageSize());
if($this->getCount()%$this->getPageSize()>0)$page++;
return $page;
}
// 显示导航条。
// 参数申明: $url 挪用页面ex:http://hello.php?showtype=main
function show_navibar($recname="笔记录",$first="首页",$pre="上页",$next="下页",$last="末页"){
$showurl = getenv("REQUEST_URI");
$tmppos = strpos($showurl,"&rscnt=");
if(!$tmppos)
$tmppos = strpos($showurl,"?rscnt=");
if($tmppos)
$showurl = substr($showurl,0,$tmppos);
$url = $showurl;
$page = $this->getCurPage();
$pagecnt = $this->getPageCount();
$cnt = $this->getCount();
if($cnt < 0) // 没有分页,不显示任何器材。
return;
if(!strrchr($url,"?"))
$url = $url."?";
else // url已带了参数。
$url = $url."&";
$url = $url."rscnt=".$cnt."&page=";
if($page>1){
?>
<a href=<?echo $url?>1><?=$first?></a> <a href=<?echo $url.($page-1)?>><?=$pre?></a>
<?
}
else{
?>
<?=$first?> <?=$pre?>
<?
}
if($page<$pagecnt){
?>
<a href=<?echo $url.($page+1)?>><?=$next?></a> <a href=<?echo $url.$pagecnt?>><?=$last?></a>
<?
}
else{
?>
<?=$next?> <?=$last?>
<?
}
?>
共有 <font color="#FF0000"><?=$cnt?></font> <?=$recname?>,以后<?=$page?>/<?=$pagecnt?>
第<input type=text style="width: 20px; height: 16px; font-size: 12px; color: #000000;border: 1px solid;" name=page value=<?=$page?>>页
<input type=button onclick="ice_ttttt_runto('<?=$url?>')" style="height: 16px; font-size: 12px; color: #000000;border: 1px solid;" value="Go!">
<script language=javascript>
<!--
function ice_ttttt_runto(url){
var p = self.page.value;
self.navigate(url+p);
}
--></script>
<?
}
} 对于PHP的语法结构,刚开始真的很不习惯,真搞不懂为什么每个变量之前都要加个“$”符号,每个语句写完之后都必须加上“分号”来表示此句已经结束,还有,PHP对字母的大小写是敏感的,写的时候一定要注意大小写的区别。 |
|