<script type="text/javascript">
</script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
前段时间发了一个PHP分页的,后来研究了下多列的,今天再发上去
<script type=text/javascript>
</script> <script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type=text/javascript> </script>
<?
php
require_once
(
'
Connections/lr.php
'
);
?>
<?
php
require_once
(
'
pageconfig.php
'
);
?>
<?
php
//
设定每一页显示的记录数
$pagesize
=
$meiyegeshu
;
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
//
取得记录总数$rs,计算总页数用
mysql_select_db
(
$database_lr
,
$lr
);
$rs
=
mysql_query
(
"
select count(*) from product
"
);
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
$myrow
=
mysql_fetch_array
(
$rs
);
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
$numrows
=
$myrow
[
0
];
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
//
计算总页数
$pages
=
intval
(
$numrows
/
$pagesize
);
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
if
(
$numrows
%
$pagesize
)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
$pages
++
;
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
//
设置页数
if
(
isset
(
$_GET
[
'
page
'
])){
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
$page
=
intval
(
$_GET
[
'
page
'
]);
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
}
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
else
{
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
//
设置为第一页
$page
=
1
;
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
}
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
//
计算记录偏移量
$offset
=
$pagesize
*
(
$page
-
1
);
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
//
读取指定记录数
$rs
=
mysql_query
(
"
select * from product order by articleid limit $offset,$pagesize
"
);
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
if
(
$myrow
=
mysql_fetch_array
(
$rs
))
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
{
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
$i
=
0
;
//
如果$url使用默认,即空值,则赋值为本页URL:
if
(
!
$url
){
$url
=
$_SERVER
[
"
REQUEST_URI
"
];}
//
URL分析:
$parse_url
=
parse_url
(
$url
);
$url_query
=
$parse_url
[
"
query
"
];
//
单独取出URL的查询字串
if
(
$url_query
){
//
因为URL中可能包含了页码信息,我们要把它去掉,以便加入新的页码信息。
//这里用到了正则表达式,请参考“PHP中的正规表达式”(http://www.pconline.com.cn/pcedu/empolder/wz/php/10111/15058.html)
$url_query
=
ereg_replace
(
"
(^|&)page=$page
"
,
""
,
$url_query
);
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
//
将处理后的URL的查询字串替换原来的URL的查询字串:
$url
=
str_replace
(
$parse_url
[
"
query
"
]
,
$url_query
,
$url
);
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
//
在URL后加page查询信息,但待赋值:
if
(
$url_query
)
$url
.=
"
&page
"
;
else
$url
.=
"
page
"
;
}
else
{
$url
.=
"
?page
"
;
}
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
?>
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
<
table border
=
"
0
"
width
=
"
100%
"
>
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
<
tr
>
<?
php
$j
=
0
;
do
{
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
$j
=
$j
+
1
;
$i
++
;
$w
=
$myrow
[
'
swidth
'
];
$h
=
$myrow
[
'
sheight
'
];
$m
=
$w
/
$smallpic_width
;
$n
=
$h
/
$smallpic_width
;
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
if
(
$w
>=
$smallpic_width
or
$h
>=
$smallpic_width
){
if
(
$m
>
$n
) {
$w1
=
$smallpic_width
;
$h1
=
$h
/
$m
;}
elseif
(
$m
<
$n
) {
$h1
=
$smallpic_width
;
$w1
=
$w
/
$n
;}
else
{
$w1
=
$smallpic_width
;
$h1
=
$smallpic_width
;
}
}
else
{
$w1
=
$w
;
$h1
=
$h
;
};
$pwidth
=
100
/
$meihanggeshu
;
?>
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
<
td align
=
"
center
"
width
=
"
<?php echo $pwidth?>%
"
height
=
"
120
"
valign
=
"
top
"
><
table width
=
"
100%
"
border
=
"
0
"
cellspacing
=
"
0
"
cellpadding
=
"
0
"
align
=
"
center
"
>
<
tr
>
<
td align
=
"
center
"
><
img src
=
"
<?php echo $myrow['smallpic']?>
"
width
=
"
<?php echo $w1?>
"
height
=
"
<?php echo $h1?>
"
/></
td
>
</
tr
>
<
tr
>
<
td align
=
"
center
"
><?
php
echo
$myrow
[
'
product_id
'
]
?></
td
>
</
tr
>
</
table
>
</
td
><?
php
if
(
$j
%
$meihanggeshu
==
0
) {
?>
</
tr
>
<?
php }
?>
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
<?
php
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
}
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
while
(
$myrow
=
mysql_fetch_array
(
$rs
));
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
echo
"
</table>
"
;
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
}
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
echo
"
<div align='center'>Total
"
.
$pages
.
"
pages(
"
.
$page
.
"
/
"
.
$pages
.
"
)
"
;
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
//
for ($i=1;$i< $page;$i++)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
//echo "<a href='?page=".$i."'>[".$i ."]</a> ";
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
//echo "[".$page."]";
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
//for ($i=$page+1;$i<=$pages;$i++)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
//echo "<a href='?page=".$i."'>[".$i ."]</a> ";
$first
=
1
;
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
$prev
=
$page
-
1
;
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
$next
=
$page
+
1
;
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
$last
=
$pages
;
if
(
$page
==
1
)
{
echo
"
First
"
;
}
else
{
echo
"
<a href='
"
,
$url
,
"
=
"
.
$first
.
"
'>First</a>
"
;
}
if
(
$page
==
1
){
echo
"
Pre
"
;}
else
{
echo
"
<a href='
"
,
$url
,
"
=
"
.
$prev
.
"
'>Pre</a>
"
;
}
if
(
$pages
>
$page
){
echo
"
<a href='
"
,
$url
,
"
=
"
.
$next
.
"
'>Next</a>
"
;
}
else
{
echo
"
Next
"
;}
if
(
$pages
>
$page
){
echo
"
<a href='
"
,
$url
,
"
=
"
.
$last
.
"
'>Last</a>
"
;
}
else
{
echo
"
Last
"
;}
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
echo
"
<select name=change οnchange='window.location="$url="+this.value'>
"
;
for
(
$i
=
1
;
$i
<=
$pages
;
$i
++
){
if
(
$i
==
$page
)
echo
"
<option value='$i' selected>$i/$pages</option>
"
;
else
echo
"
<option value='$i'>$i/$pages</option>
"
;
}
echo
"
</select>
"
;
echo
"
</div>
"
;
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
?>
用到了几个变量,分别是$meiyegeshu,$meihanggeshu读拼音就知道是什么了,呵呵。