主题:[原创]PHP分页
高手们,请教一下我下面的这段代码如何循环行和列,现在只能循环行,谢谢啦!
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="597" height="231" align="left" valign="middle" background="images/r10.jpg"><table width="200" border="0" cellspacing="0" cellpadding="0">
<?php
$execc="select count(*) from hz_zp";
$resultc=mysql_query($execc);
$rsc=mysql_fetch_array($resultc);
$num1=$rsc[0]; //num1表示总记录数
$pagesize=3;//pagesize表示每页显示的记录数
//page表示传递过来的页码
if(empty($_GET['page']))
{
$page=0;
}
else
{
$page=$_GET['page'];
if($page<0)$page=0;
if($page>=ceil($num1/$pagesize))$page=ceil($num1/$pagesize)-1;//因为page是从0开始的,所以要-1
}
//实现分页效果中间代码
$query="select * from hz_zp order by id desc limit ".($page*$pagesize).",$pagesize";
$result=mysql_query($query);//执行查询,返回结果给result
$num=mysql_num_rows($result);//num区别于上面的num1,这是表示当前页显示的数目
if($result)
{
for($i=0;$i<$num;$i++)
{
mysql_data_seek($result,$i);//表示取的是第i行的数据
$date=mysql_fetch_array($result);
//$a_rows=mysql_affected_rows($result);
//for ($i=0;$i<$rows;$i++)
// {
@mysql_data_seek($result,$i);
$data=mysql_fetch_array($result);
$id=$data[id];
$img=$data[img];
$url=$data[url];
$shuoming=$data[shuoming];
//$content=str_replace("\n\r","<br>",$content);
//$content=str_replace(" "," ",$content);
//echo nl2br($content);
?>
<tr>
<td align="center" valign="middle"><table width="200" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="180" align="center" valign="middle"><a href="<?php echo $url ?>" target="_blank"><img src="uploadpic/<?php echo $img ?>" width="188" height="158" border="0" class="biaoyi1"></a></td>
</tr>
<tr>
<td height="20" align="center" valign="middle"><a href="<?php echo $url ?>" target="_blank"><?php echo $shuoming ?></a></td>
</tr>
</table></td>
</tr> <?php
}
}
?>
</table></td>
</tr>
<tr>
<td height="25" align="center" valign="middle" background="images/r10.jpg"><?php
echo "<table border='0' align='center'><tr><td align='center'>";
echo("共有 <font color=red>".$num1."</font> 条记录,每页显示 <font color=red>".$pagesize."</font> 条,当前第 <font color=red>".($page+1)."</font>/<font color=blue>".ceil($num1/$pagesize)."</font> 页 ");
if($page!=0) echo("<a href='?page=0'>首页</a> ");
else echo("首页 ");
if($page>0) echo("<a href=?page=".($page-1).">上一页</a> ");
else echo("上一页 ");
if($page<ceil($num1/$pagesize)-1) echo("<a href=?page=".($page+1).">下一页</a> ");
else echo("下一页 ");
if($page!=ceil($num1/$pagesize)-1) echo("<a href=?page=".(ceil($num1/$pagesize)-1).">尾页</a> ");
else echo("尾页 ");
echo "</td></tr></table>";
?> </td>
</tr>
<tr>
<td height="25" align="center" valign="middle" background="images/r10.jpg"> </td>
</tr>
</table>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="597" height="231" align="left" valign="middle" background="images/r10.jpg"><table width="200" border="0" cellspacing="0" cellpadding="0">
<?php
$execc="select count(*) from hz_zp";
$resultc=mysql_query($execc);
$rsc=mysql_fetch_array($resultc);
$num1=$rsc[0]; //num1表示总记录数
$pagesize=3;//pagesize表示每页显示的记录数
//page表示传递过来的页码
if(empty($_GET['page']))
{
$page=0;
}
else
{
$page=$_GET['page'];
if($page<0)$page=0;
if($page>=ceil($num1/$pagesize))$page=ceil($num1/$pagesize)-1;//因为page是从0开始的,所以要-1
}
//实现分页效果中间代码
$query="select * from hz_zp order by id desc limit ".($page*$pagesize).",$pagesize";
$result=mysql_query($query);//执行查询,返回结果给result
$num=mysql_num_rows($result);//num区别于上面的num1,这是表示当前页显示的数目
if($result)
{
for($i=0;$i<$num;$i++)
{
mysql_data_seek($result,$i);//表示取的是第i行的数据
$date=mysql_fetch_array($result);
//$a_rows=mysql_affected_rows($result);
//for ($i=0;$i<$rows;$i++)
// {
@mysql_data_seek($result,$i);
$data=mysql_fetch_array($result);
$id=$data[id];
$img=$data[img];
$url=$data[url];
$shuoming=$data[shuoming];
//$content=str_replace("\n\r","<br>",$content);
//$content=str_replace(" "," ",$content);
//echo nl2br($content);
?>
<tr>
<td align="center" valign="middle"><table width="200" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="180" align="center" valign="middle"><a href="<?php echo $url ?>" target="_blank"><img src="uploadpic/<?php echo $img ?>" width="188" height="158" border="0" class="biaoyi1"></a></td>
</tr>
<tr>
<td height="20" align="center" valign="middle"><a href="<?php echo $url ?>" target="_blank"><?php echo $shuoming ?></a></td>
</tr>
</table></td>
</tr> <?php
}
}
?>
</table></td>
</tr>
<tr>
<td height="25" align="center" valign="middle" background="images/r10.jpg"><?php
echo "<table border='0' align='center'><tr><td align='center'>";
echo("共有 <font color=red>".$num1."</font> 条记录,每页显示 <font color=red>".$pagesize."</font> 条,当前第 <font color=red>".($page+1)."</font>/<font color=blue>".ceil($num1/$pagesize)."</font> 页 ");
if($page!=0) echo("<a href='?page=0'>首页</a> ");
else echo("首页 ");
if($page>0) echo("<a href=?page=".($page-1).">上一页</a> ");
else echo("上一页 ");
if($page<ceil($num1/$pagesize)-1) echo("<a href=?page=".($page+1).">下一页</a> ");
else echo("下一页 ");
if($page!=ceil($num1/$pagesize)-1) echo("<a href=?page=".(ceil($num1/$pagesize)-1).">尾页</a> ");
else echo("尾页 ");
echo "</td></tr></table>";
?> </td>
</tr>
<tr>
<td height="25" align="center" valign="middle" background="images/r10.jpg"> </td>
</tr>
</table>