Heim  >  Artikel  >  Backend-Entwicklung  >  这个变量是怎么来的

这个变量是怎么来的

WBOY
WBOYOriginal
2016-06-23 13:44:50836Durchsuche


下面这段代码中 if(isset($_GET['n_page'])){                         //判断当前页码
n_page是从哪来的,我查了一下不是数据表中的字段,它到底是怎么来的,难道是随便定义的一个玩意吗

<?phpsession_start();include_once("conn/conn.php");?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link href="css/viewmeeting.css" type="text/css" rel="stylesheet" /><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>无标题文档</title></head><body><h3>会议信息浏览</h3><?php$sqlview="select * from tb_meeting_info";$num=2;                                                 //每页显示最大记录数  if(isset($_GET['n_page'])){	                        //判断当前页码   $c_page = $_GET['n_page'];					            //将$n_page赋给变量$c_apge  }else{		$c_page = 1;								    //初始化变量$c_page	    } $l_rst = $conn -> PageExecute($sqlview,$num,$c_page);	//执行pageExecute函数$rst_view = $conn->execute($sqlview);$record=count($rst_view->GetRows());                    //获取总记录数if($record==0){echo "<span class=\"norecord\">当前没有任何记录</span>";}else{?><table width="728" border="0" cellspacing="0" cellpadding="0" bordercolor="#66CC00">  <tr class="tableheader">    <td width="55" align="center" height="25">会议编号</td>    <td width="60" align="center">会议名称</td>    <td width="60" align="center">部门名称</td>    <td width="80" align="center">会议地点</td>    <td width="80" align="center">会议日期</td>    <td width="45" align="center">主持人</td>    <td width="60" align="center">出席人员</td>    <td width="45" align="center">记录人</td>    <td width="120" align="center">会议摘要</td>	<td width="60" align="center">查看详情</td>  </tr><?phpwhile(!$l_rst->EOF){?>  <tr>    <td height="30"><?php echo $l_rst->fields[0]; ?></td>    <td height="30"><?php echo $l_rst->fields[1]; ?></td>    <td height="30"><?php echo $l_rst->fields[2]; ?></td>    <td height="30"><?php echo $l_rst->fields[3]; ?></td>    <td height="30"><?php echo $l_rst->fields[4]; ?></td>    <td height="30"><?php echo $l_rst->fields[5]; ?></td>    <td height="30"><?php echo $l_rst->fields[6]; ?></td>    <td height="30"><?php echo $l_rst->fields[7]; ?></td>    <td height="30"><?php echo $l_rst->fields[8]; ?></td>	<td height="30" align="center"><a href="#" onclick="javascript:Wopen=open('showinfo.php?id=<?php echo $l_rst->fields[0]; ?>','','height=720,width=1004,scrollbars=no');"><img src="images/xiazai.gif" width="26"    style="max-width:90%" border="0" alt="详情"></a></td>  </tr><?php   $l_rst->movenext();   } ?></table><div class="sepa_page"><table>  <tr>    <td>  <font color='#999999'>当前是第<?php echo $l_rst -> absolutePage(); ?>页/一共<?php echo $l_rst -> LastPageNo(); ?>页</font><?php		if(!$l_rst -> AtfirstPage()){					//如果当前页不是首页?><!--  输出向上翻页超链接  -->		<a href ="<?php echo "?lmbs=$_GET[lmbs]&n_page=1" ?>"> 首页 </a>		<a href ="<?php echo "?lmbs=$_GET[lmbs]&n_page=".($l_rst -> absolutePage() - 1); ?>"> 上一页 </a><!--  ----------------------------  --><?php		}		if(!$l_rst -> AtlastPage()){					//如果当前页不是尾页?><!--  输出向下翻页超链接  -->		<a href = "<?php echo "?lmbs=$_GET[lmbs]&n_page=".($l_rst -> absolutePage() + 1); ?>"> 下一页 </a>		<a href ="<?php echo "?lmbs=$_GET[lmbs]&n_page=".($l_rst -> LastPageNo());?>"> 尾页 </a>	<!--  -----------------------------  --><?php		}?><?php}?>      </td>	  <td width="100" align="right"><span style="color:#FF0000">点此导出报表>>></span></td>	  <td width="60">		   <a href="createform.php"><img  align="bottom"src="images/out_15.jpg"    style="max-width:90%"  style="max-width:90%" border="0" / alt="这个变量是怎么来的" ></a>		</td>	 </tr>  </table></div></body></html>


回复讨论(解决方案)

看看session里的值, 还有是哪个页面传进来的,看一下

这个应该是分页页码参数,类似这样的
http://index.php?n_page=2,3,4......
当n_page为第一页的时候,通常是获取不到参数的,所以需要判断一下$_GET['n_page']是否存在,不存在则为第一页。如果存在,则根据获取到的值,显示对应页的内容。

你不是有这样的语句吗?
"> 首页 
$_GET['n_page'] 就是这样来的

通过页面链接传的值呀?
$_GET取值;没取到的清楚下,默认为第一页
你后面的分页里面都有呀

其实是由"> 首页 来的
这涉及到url传值的知识,当一个链接传到地址栏的时候$_GET[ ]数组就会截取它,因为$_GET[ ]数组是全局变量数组,专门负责截获地址栏中的值的。
只可惜大家都没有答对,上面是我悟出来的。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn