Maison > développement back-end > tutoriel php > PHP查询提交给自身展示结果并分页为何点击下一页显示全部内容

PHP查询提交给自身展示结果并分页为何点击下一页显示全部内容

WBOY
Libérer: 2016-06-23 13:28:43
original
1877 Les gens l'ont consulté

背景:在一ldt.php页面中有同一个form,两个按钮分别在提交的时候给到两个不同页面。一个按钮是插入数据库,一个按钮是查询并提交给自己在本页中展示出结果内容,有分页函数,提交后跳转过来的第一页是正常显示查询条件对应的结果的,但是点击下一页等就会显示数据库全部结果。我觉得应该是分页的时候没有带上参数,但是不知道怎么带,把部分源代码贴上来,请大神修改一下。
1、js提交不同页面:
<script></script>
 <script> <br /> function submitit1() <br /> //交由程序1处理 <br /> { <br /> document.myForm.action = "其他.php" <br /> document.myForm.submit(); <br /> } <br /> function submitit2() <br /> //交由本页处理 <br /> { <br /> document.myForm.action = "ldt.php" <br /> document.myForm.submit(); <br /> <br /> } <br /> </script>
2、分页函数:

$page = $_GET["page"]; 
function Page($rows,$page_size){ 
global $page,$select_from,$select_limit,$pagenav; 
$page_count = ceil($rows/$page_size); 
if($page  if($page >= $page_count) $page = $page_count; 
$select_limit = $page_size; 
$select_from = ($page - 1) * $page_size.','; 
$pre_page = ($page == 1)? 1 : $page - 1; 
$next_page= ($page == $page_count)? $page_count : $page + 1 ; 
$pagenav .= "第 $page/$page_count 页 共 $rows 条记录 "; 
$pagenav .= "首页 "; 
$pagenav .= "前一页 "; 
$pagenav .= "后一页 "; 
$pagenav .= "末页"; 
$pagenav.=" 跳到


回复讨论(解决方案)

你贴出的两段代码,基本与解决问题无关

你只需要用某种方法保存下查询时的筛选条件就可以了

保存后赋给谁呢

include 'tof3/header.php';  $_SESSION['hcrdtbj']=$_GET['hcrdtbj'];
$hcrdtbj=$_SESSION['hcrdtbj'];


?>
nbsp;HTML>

 




<script></script>
 <script> <br /> function submitit1() <br /> //交由程序1处理 <br /> { <br /> document.myForm.action = "hcoutinsert.php" <br /> document.myForm.submit(); <br /> } <br /> function submitit2() <br /> //交由程序2处理 <br /> { <br /> document.myForm.action = "ldt.php" <br /> document.myForm.submit(); <br /> <br /> } <br /> </script>
<script></script>
<script></script>
<script><!-- <br /> $(document).ready(function(){ <br /> _w_table_rowspan("#spdata",2); <br /> <br /> }); <br /> // --> <br /> </script>  






 















  

    
领用详情

  

  





 

  


  

  

  

<script> <br /> addressInit('scene','purpose','catalogue','hc'); <br /> </script>

  

  
        



  


  
 

 
 
  
  





  















$page = $_GET["page"]; 
function Page($rows,$page_size){ 
global $page,$select_from,$select_limit,$pagenav; 
$page_count = ceil($rows/$page_size); 
if($page  if($page >= $page_count) $page = $page_count; 
$select_limit = $page_size; 
$select_from = ($page - 1) * $page_size.','; 
$pre_page = ($page == 1)? 1 : $page - 1; 
$next_page= ($page == $page_count)? $page_count : $page + 1 ; 
$pagenav .= "第 $page/$page_count 页 共 $rows 条记录 "; 
$pagenav .= "首页 "; 
$pagenav .= "前一页 "; 
$pagenav .= "后一页 "; 
$pagenav .= "末页"; 
$pagenav.=" 跳到";

if($row['scene']=="VIP耗材"){
echo "";}
else{
echo "";}

echo "";

if($row['dtime'] ==$rowv['dtime'] || $row['dtime'] ==$rowp['dtime'] ) {

echo "";

}
else{

echo "";

}



echo "";
mysql_close($conn);
mysql_free_result($rst);
mysql_free_result($rstv);
mysql_free_result($rstp);
 




?>
用户名 归属 场景 类型 明细 领用数 原因 操作人 时间
{$row['customer']} {$row['scene']} {$row['purpose']} {$row['catalogue']} 的库存详情' style='color:white;'/a>{$row['hc']}的库存详情'/a>{$row['hc']} {$row['number']} {$row['reason']} {$row['person']} {$row['dtime']}PHP查询提交给自身展示结果并分页为何点击下一页显示全部内容
{$row['dtime']}
$pagenav










<?phpinclude 'tof3/header.php';  $_SESSION['hcrdtbj']=$_GET['hcrdtbj'];$hcrdtbj=$_SESSION['hcrdtbj'];?><!DOCTYPE HTML><html><head> <meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"/><script type="text/javascript" src="js/hcselect.js"></script> <script>       function submitit1()       //交由程序1处理            {           document.myForm.action = "hcoutinsert.php"           document.myForm.submit();       }       function submitit2()       //交由程序2处理            {           document.myForm.action = "ldt.php"           document.myForm.submit();       }   </script><script type="text/javascript" src="js/jquery-1.8.3.min.js" ></script><script type="text/javascript" src="js/tablespan.js" ></script><script type="text/javascript"><!--      $(document).ready(function(){           _w_table_rowspan("#spdata",2);      });  // -->  </script>  <meta charset="utf-8"></head><BODY> <div id="main"><div id="top"><div id="headerborder"><div id="hl"></div><div id="hm"></div><div id="hr"><!--<span style="text-align:right;">  <input type="button"  onmouseover="this.className='on1' " onmouseout="this.className='out1'" style="width:80px; height:40px; font-size:12px; font-family:'Microsoft YaHei UI'; border:1px solid #CDCDCD;"  value="返回导航" /></span>--></div></div><!--移动设备--><div id="header">  <div id="header1">    <div id="inheader11">领用详情</div><div id="inheader1" onclick="location.href='rdt.php'" style="cursor:pointer;"><a style="color:#999;">库存详情</a></div>  </div>  <form name="myForm" method="post"><div id="header2"></div><div id="header"><div id="inheader22"><div id="inheader23"> <input  name="customer" style=" width:80px; vertical-align:middle;"   value="用户名"  id="userChooser" class="oc_common oc_userchooser"  >  <select id="scene" name="scene" style="vertical-align:middle;" ></select>  <select id="purpose" name="purpose" style="vertical-align:middle;"></select>  <select id="catalogue" name="catalogue" style="vertical-align:middle;">  </select>  <select id="hc" name="hc" style="vertical-align:middle;">  </select><script type="text/javascript">addressInit('scene','purpose','catalogue','hc');</script>  <input  name="number"  style=" width:60px; vertical-align:middle;" onkeyup="value=this.value.replace(/\D+/g,'')" value="数量" onfocus="this.value='';" onblur="if(this.value==''){this.value='数量'}" />          <select name="reason" style="vertical-align:middle;" >            <option>原因</option>            <option>新领</option>            <option>更换</option>            <option>借用</option>            <option>测试</option>        </select></div><div id="inheader24"><div id="inheader25">  <input name="mysubmit" type="button" value="领用" title="领用每项必填" onClick=submitit1() onmouseover="this.className='on1' " onmouseout="this.className='out1'"  style="cursor:pointer;outline:none;width:40px; height:40px;border-radius:50%; font-size:12px; vertical-align:middle;  font-family:'Microsoft YaHei UI'"/></div><div id="inheader25">  <input name="mysubmit" type="button" value="查询"  title="查询条件忽略数量" onClick=submitit2() onmouseover="this.className='on1' " onmouseout="this.className='out1'"  style="cursor:pointer;outline:none;width:40px;height:40px; border-radius:50%;font-size:12px; vertical-align:middle;  font-family:'Microsoft YaHei UI'"/> </div> <div id="inheader25">   <input name="导出" type="button" value="导出" title="导出当前页面内容" onclick="location.href='exportl.php' " onmouseover="this.className='on1' " onmouseout="this.className='out1'"  style=" cursor:pointer;outline:none; width:40px; height:40px;border-radius:50%;vertical-align:middle; font-size:12px;  font-family:'Microsoft YaHei UI'" />  </div></div></div></div></form>  </div></div><div id="m"><table id="spdata" align="center" width="800px" border="0px" ><th style="width:140px;">用户名</th><th style="width:55px;">归属</th><th style="width:55px;">场景</th><th style="width:90px;">类型</th><th style="width:110px;">明细</th><th style="width:40px;">领用数</th><th style="width:50px;">原因</th><th style="width:100px;">操作人</th><th style="width:160px;">时间</th><?php $page = $_GET["page"]; function Page($rows,$page_size){ global $page,$select_from,$select_limit,$pagenav; $page_count = ceil($rows/$page_size); if($page <= 1 || $page == '') $page = 1; if($page >= $page_count) $page = $page_count; $select_limit = $page_size; $select_from = ($page - 1) * $page_size.','; $pre_page = ($page == 1)? 1 : $page - 1; $next_page= ($page == $page_count)? $page_count : $page + 1 ; $pagenav .= "第 $page/$page_count 页 共 $rows 条记录 "; $pagenav .= "<a href='?page=1&hcrdtbj=$_SESSION[hcrdtbj]'>首页</a> "; $pagenav .= "<a href='?page=$pre_page&hcrdtbj=$_SESSION[hcrdtbj]'>前一页</a> "; $pagenav .= "<a href='?page=$next_page&hcrdtbj=$_SESSION[hcrdtbj]'>后一页</a> "; $pagenav .= "<a href='?page=$page_count&hcrdtbj=$_SESSION[hcrdtbj]'>末页</a>"; $pagenav.=" 跳到<select name='topage' size='1' onchange='window.location=\"?page=\"+this.value+\"&hcrdtbj=$_SESSION[hcrdtbj]\"'>\n"; for($i=1;$i<=$page_count;$i++){ if($i==$page) $pagenav.="<option value='$i' selected>$i</option>\n"; else $pagenav.="<option value='$i'>$i</option>\n"; } } // Page分页函数 // 使用示例 if (!$conn= mysql_connect("localhost", "r12" ,"22222")) die('数据库选择失败!'); if (!mysql_select_db("ccccccc", $conn)) die('数据库选择失败!'); // 用Page函数计算出 $select_from 从哪条记录开始检索、$pagenav 输出分页导航$sqlv = "SELECTmax(dtime) as dtimeFROMhaocaiwhere scene='VIP耗材'ORDER BYdtime DESC "; $rstv = mysql_query($sqlv,$conn); $rowv=mysql_fetch_assoc($rstv);$sqlp = "SELECTmax(dtime) as dtimeFROMhaocaiwhere scene='普通耗材'ORDER BYdtime DESC "; $rstp = mysql_query($sqlp,$conn); $rowp=mysql_fetch_assoc($rstp);//任意条件查询组合if(!empty($hcrdtbj))    {     if(strstr($hcrdtbj,"VIP耗材"))       {        $hcr=substr($hcrdtbj, 9);        $scener=mb_substr($hcrdtbj, 0, 5, 'utf-8');         }     else        {        $hcr=substr($hcrdtbj,12);        $scener=mb_substr($hcrdtbj, 0, 4, 'utf-8');        }	$a="where scene='$scener' and hc='$hcr'";$_SESSION['where']=	"where scene='$scener' and hc='$hcr'";}else{if($_POST['customer']=="用户名" && !empty($_POST['scene']) && !empty($_POST['purpose'])&& !empty($_POST['catalogue'])&& !empty($_POST['hc'])&&  $_POST['reason']!=="原因"){     $a="where scene='$_POST[scene]' and purpose='$_POST[purpose]' and catalogue='$_POST[catalogue]'  and hc='$_POST[hc]'  and reason='$_POST[reason]'"; $_SESSION['where']="where scene='$_POST[scene]' and purpose='$_POST[purpose]' and catalogue='$_POST[catalogue]'  and hc='$_POST[hc]'  and reason='$_POST[reason]'"; $_SESSION['hcrdtbj']="$_POST[scene]$_POST[purpose]$_POST[catalogue]$_POST[hc]$_POST[reason]";    } else{     $a=""; $_SESSION['where']="order by dtime desc";    }    }$rows = mysql_num_rows(mysql_query("select customer,scene,purpose,catalogue,hc,number,reason,person,dtime from haocai  $a ")); Page($rows,35); $sql = "select customer,scene,purpose,catalogue,hc,number,reason,person,dtime from haocai $a order by scene,dtime desc limit $select_from $select_limit "; $rst = mysql_query($sql); while($row=mysql_fetch_assoc($rst)){ $vip_style = $row['scene']=="VIP耗材" ? ' style=" background-color:#096;color:white;"' : '';echo "<tr><td $vip_style>{$row['customer']}</td><td $vip_style>{$row['scene']}</td><td $vip_style>{$row['purpose']}</td><td $vip_style>{$row['catalogue']}</td>";if($row['scene']=="VIP耗材"){echo "<td $vip_style><a href='rdt.php?hcldtbj=$row[scene]$row[hc]' title='点击查看<$row[scene]/$row[hc]>的库存详情' style='color:white;'/a>{$row['hc']}</td>";}else{echo "<td $vip_style><a href='rdt.php?hcldtbj=$row[scene]$row[hc]' title='点击查看<$row[scene]/$row[hc]>的库存详情'/a>{$row['hc']}</td>";}echo "<td $vip_style>{$row['number']}</td><td $vip_style>{$row['reason']}</td><td $vip_style>{$row['person']}</td>";if($row['dtime'] ==$rowv['dtime'] || $row['dtime'] ==$rowp['dtime'] ) {echo "<td $vip_style>{$row['dtime']}<img  src='pic/new.gif'/ alt="PHP查询提交给自身展示结果并分页为何点击下一页显示全部内容" ></td></tr>";}else{echo "<td $vip_style>{$row['dtime']}</td></tr>";	}	} echo "<tr border=0><td colspan=9 align='right'>$pagenav</td></tr>";mysql_close($conn);mysql_free_result($rst);mysql_free_result($rstv);mysql_free_result($rstp); ?></table></div></div></body></html>
Copier après la connexion

source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal