$MM_ParemName='';
$MM_removelist="&index=";
if($MM_ParemName!='')$MM_removelist.="&".strtolower($MM_ParemName)."=";//???为什么要这样写不太明白
$MM_keepURL="";
$MM_keepForm="";
$MM_keepBoth="";
$MM_keepNone="";
/*以上$MM_ParemName,$MM_removelist="index=",$MM_keepURL="";$MM_keepForm="";$MM_keepBoth="";$MM_keepNone="";
?????这些变量有的设置为空,这样写的目的是什么我看不明白。*/
reset($_GET); //将数组的内部指针指向第一个单元
while(list($key,$val)= each($_GET)){
$nextItem="&".strtolower($key)."=";
if(!stristr($MM_removeList,$nextItem)){ //???这个地方看的不是很明白,为什么要加上这句话
$MM_keepURL.="&".key."=".urlencode($val);//}
}
if(isset($_POST)){
reset($_POST);
while(list($key,$val)= each($_POST)){
$nextItem="&".strtolower($key)."=";//
if(!stristr($MM_removeList,$nextItem)){//???这个地方看的不是很明白,为什么要加上这句话
$MM_keepForm.="&".key."=".urlencode($val);//
}
}
}
$MM_keepBoth=$MM_keepURL."&".$MM_keepForm;//这个地方看的不是很明白
if(strlen($MM_keepBoth)>0)$MM_keepBoth=substr($MM_keepBoth,1);//???这个地方看的不是很明白
if(strlen($MM_keepURL)>0)$MM_keepURL=substr($MM_keepURL,1);//???这个地方看的不是很明白
if(strlen($MM_keepForm)>0)$MM_keepForm=substr($MM_keepForm,1);//???这个地方看的不是很明白?><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>网上书店数据库的演示实现增删查改功能</title>
</head>
<body bgcolor="#f4f4f4">
<table width="760px" border="1" align="center">
<tr>
<td width="760" height="98" align="center" colspan="4">网上书店网上书店数据库的演示实现增删查改功能</td>
</tr>
<tr>
<td width="760" height="98" align="center"><a href="index.php">首页</a>
</td>
<td width="760" height="98" align="center"><a href="allBooklist.php">全部图书</a>
</td>
<td <td width="760" height="98" align="center"><a href="insertBook.php">插入图书</a>
</td>
<td <td width="760" height="98" align="center"><a href="deleteBook.php">删除图书</a>
</td>
</tr>
<tr>
<td colspan="4" align="center">
<form id="form1"name="form1"method="post"action="">
<tr>
<td>
书名
</td>
<td>
作者
</td>
<td>
图书类型
</td>
<td>
删除
</td>
</tr>
<?php do{?>
<tr>
<td><?php echo $row_Book['BookName'];?>
</td>
<td><?php echo $row_Book['BookAuthor'];?>
</td>
<td><?php echo $row_Book['BookType'];?><input type="hidden" name="BookID" id="BookID" Value="<?php echo $row_Book['BookID'];?>"/>
</td><td><a href="delete.php?<?php echo $MM_keepURL.(($MM_keepURL!="")?"&":"")."BookID=".$row_Book['BookID']?>">删除 </a>// ???这个地方看的不是很明白
</td></tr><?php } while($row_Book=mysql_fetch_assoc($Book));?>
</form>
</td>
</tr>
<tr>
<td colspan="4">
<hr/>
</td>
</tr>
<tr>
<td colspan="4"></td>
</tr>
</table>
</html>
<?php
mysql_free_result($Book);//释放结果集内存。
?>
整个这段代码呢,就是保存页面跳转信息,这一点我是清楚的,但是我上面标注的几处,就是标注问号的地方,,就是看不太明白,还希望高手给指点一下,并且说的详细一点,我也是刚学不久。谢谢!

解决方案 »

  1.   

    reset($_GET); //将数组的内部指针指向第一个单元
    while(list($key,$val)= each($_GET)){
    $nextItem="&".strtolower($key)."=";
    if(!stristr($MM_removeList,$nextItem)){ //???这个地方看的不是很明白,为什么要加上这句话
    $MM_keepURL.="&".$key."=".urlencode($val);//
     
    }
    }
    if(isset($_POST)){
    reset($_POST);
    while(list($key,$val)= each($_POST)){
    $nextItem="&".strtolower($key)."=";//
    if(!stristr($MM_removeList,$nextItem)){//???这个地方看的不是很明白,为什么要加上这句话
    $MM_keepForm.="&".$key."=".urlencode($val);//
    }
    }
    这两段分别从$_GET、$_POST数组中构造出 url 参数串
    if(!stristr($MM_removeList,$nextItem)){
    表示加入过的就不再加入$MM_keepBoth=$MM_keepURL."&".$MM_keepForm;//这个地方看的不是很明白
    将上面不同来源生成的url参数攒连接起来开始的疑问,由于你没给全代码,意义不是很明确。总之是初始化一些变量
    也可能是作者改变了算法,原算法的语句没有删去本身这段代码是很垃圾的,php5 提供了 http_build_query 用于构造 url 参数串
    不用岂不可惜
      

  2.   

    跟我收集的一段代码很类似,
    此代码是php4语法写的,在国外的一个收费网店系统CRELoaded中有类似函数,
    function tep_get_all_get_params($exclude_array = '') {
    global $HTTP_GET_VARS;if ($exclude_array == '') $exclude_array = array();$get_url = '';reset($HTTP_GET_VARS);
    while (list($key, $value) = each($HTTP_GET_VARS)) {
    if (($key != tep_session_name()) && ($key != 'error') && (!in_array($key, $exclude_array))) $get_url .= $key . '=' . $value . '&';
    }return $get_url;
    }使用方法tep_get_all_get_params(array('sort'))这么写就表示获取除了sort参数外的所有地址栏参数