首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > PHP >

php分页显示,请教这怎么解决page未定义

2013-01-18 
php分页显示,请问这如何解决page未定义?link hrefcss/style.css relstylesheet?php include(con

php分页显示,请问这如何解决page未定义?
<link href="css/style.css" rel="stylesheet">
<?php 
include("conn/conn.php");
?>
<table width="563" height="587" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="563" height="587" valign="top" bgcolor="#FFFFFF"><table width="563" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="563" height="27" background="Images/fufei.gif">&nbsp;</td>
      </tr>
      <tr>
        <td height="96" align="center" valign="top"><br>
          <?php
$date1=date("Y-m-d");
$sgsql=mysql_query("select * from tb_leaguerinfo  where type='公寓信息' and showday>='$date1' and checkstate=1 ");
$sginfo=mysql_fetch_array($sgsql);
if($sginfo){
do{
?>
          <table width="540" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td height="26"><span class="style1">『公寓信息』</span><span class="style8">&nbsp;<?php echo $sginfo[title];?>&nbsp;</span><span class="style6">&nbsp;<?php echo $sginfo[edate];?></span></td>
            </tr>
            <tr>
              <td height="26">&nbsp;&nbsp;&nbsp;<span class="style5">&nbsp;<?php echo $sginfo[content];?></span></td>
            </tr>
            <tr>
              <td height="26">&nbsp;<span class="style8">联系人:<?php echo $sginfo[linkman];?>&nbsp;&nbsp;&nbsp;联系电话:<?php echo $sginfo[tel];?></span></td>
            </tr>
            <tr>
              <td height="3" background="Images/line1.gif"></td>
            </tr>
          </table>
          <?php
}while($sginfo=mysql_fetch_array($sgsql));
}else{
?>
          <table width="540" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td align="center">暂无电脑信息资源!</td>
            </tr>
          </table>


          <?php
}
?>
</td>
      </tr>
      <tr>
        <td align="center" valign="top"><table width="560" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td height="87" background="Images/guanggao.gif">&nbsp;</td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td height="27" background="Images/mian.gif">&nbsp;</td>
      </tr>
      <tr>
        <td height="140" align="center" valign="top">
<br>
<?php
$sql=mysql_query("select count(*) as total from tb_info where type='公寓信息' and checkstate=1");
$info=mysql_fetch_array($sql);
$total=$info['total'];
$page = 0;
$pagesize=4;
 if ($total<=$pagesize){
    $pagecount=1;
 } 
if(($total%$pagesize)!=0){
  $pagecount=intval($total/$pagesize)+1;
}else{
 $pagecount=$total/$pagesize;
}
if(($_GET['page'])==""){//这里是第75 行 报错page未定义
  $page=1;
}else{
$page=intval($_GET['page']);
}
$gsql=mysql_query("select * from tb_info where type='电脑信息' and checkstate=1 order by edate desc limit ".($page-1)*$pagesize.",$pagesize");
$ginfo=mysql_fetch_array($gsql);
if($ginfo){
  do{
?>
          <table width="540" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td height="26"><span class="style1">『电脑信息』</span><span class="style8">&nbsp;<?php echo $ginfo[title];?>&nbsp;</span><span class="style6">&nbsp;<?php echo $ginfo[edate];?></span></td>
            </tr>
            <tr>
              <td height="26">&nbsp;&nbsp;&nbsp;<span class="style5">&nbsp;<?php echo $ginfo[content];?></span></td>
            </tr>
            <tr>
              <td height="26">&nbsp;<span class="style8">作者:<?php echo $ginfo[linkman];?>&nbsp;&nbsp;&nbsp;联系电话:<?php echo $ginfo[tel];?></span></td>
            </tr>
            <tr>
              <td height="3" background="Images/line1.gif"></td>


            </tr>
          </table>
<?php
}while($ginfo=mysql_fetch_array($gsql));
?>
<table width="543" height="27" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="543" height="27" colspan="3" align="right"> &nbsp; 共有&nbsp;
        <?php
   echo $total;
  ?>
&nbsp;条&nbsp;每页显示&nbsp;<?php echo $pagesize;?>&nbsp;条&nbsp;第&nbsp;<?php echo $page;?>&nbsp;页/共&nbsp;<?php echo $pagecount; ?>&nbsp;页
      <?php
  if($page>=2)
  {
  ?>
      <a href="index.php?page=1" title="首页"></a><a href="index.php?page=<?php echo $page-1;?>" title="前一页">
      <?php
  }
   if($pagecount<=4){
    for($i=1;$i<=$pagecount;$i++){
  ?>
      <a href="index.php?page=<?php echo $i;?>"><?php echo $i;?></a>
      <?php
     }
   }else{
   for($i=1;$i<=4;$i++){ 
  ?>
      <a href="index.php?page=<?php echo $i;?>"><?php echo $i;?></a>
      <?php }?>
      <a href="index.php?page=<?php echo $page-1;?>" title="后一页"></a> <a href="index.php?page=<?php echo $pagecount;?>" title="尾页"></a>
      <?php }?></td>
  </tr>
</table>
<?php
}
else{
?>
<table width="540" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td align="center">暂无电脑信息资源!</td>
  </tr>
</table>
<?php
}
?>
</td>
      </tr>
    </table>
    </td>
  </tr>
</table>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

报错提示:

Notice: Undefined index: page in D:\xampp\htdocs\Computer\main.php on line 75

分页显示,请问这如何解决未定义!




[解决办法]
if(($_GET['page'])==""){//这里是第75 行 报错page未定义
  $page=1;
}else{
$page=intval($_GET['page']);
}

改为
$page = isset($_GET['page']) ? intval($_GET['page']) : 1; //取得传入的 page
if(!$page) $page = 1; //防止非法的 page 值,比如是 ?page=abc

[解决办法]
$page = empty($_GET['page'])?'0':1;
把75行那改改吧
[解决办法]
这个是警告,不是错误,不妨碍你程序的运行,你可以把程序警告给关闭。 display_error(0); 


或者在那行先判断是否有page变量  $page = isset($_GET['page']) ? intval($_GET['page']) : 1 ;

热点排行