国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設計 > 正文

復雜檢索數(shù)據(jù)并分頁顯示的處理方法

2019-11-18 21:43:30
字體:
來源:轉載
供稿:網(wǎng)友
系統(tǒng)標題:復雜檢索數(shù)據(jù)并分頁顯示的處理方法
系統(tǒng)功能:利用臨時表檢索數(shù)據(jù)庫數(shù)據(jù),然后分頁顯示的方法:
處理方法:采用臨時表存放數(shù)據(jù)中間結果,根據(jù)中間結果顯示數(shù)據(jù)
          數(shù)據(jù)的顯示采用隔行的方式處理
處理優(yōu)點:對于復雜的查詢,特別是涉及到多表的數(shù)據(jù)查詢,如果直接使用查詢條件,系統(tǒng)的
          開銷將很大,利用臨時表把數(shù)據(jù)先保存,然后處理。這樣對數(shù)據(jù)庫的查詢只要開銷一次。
使用方法:只要把連接數(shù)據(jù)庫的用戶信息和數(shù)據(jù)表改變即可使用
        
<?
  //連接數(shù)據(jù)庫
  $dbh =  MySQL_connect('localhost:3306','root','');
  mysql_select_db('test');  

  //把數(shù)據(jù)檢索的結果保存到臨時表中
   $ls_sql  = ' create temporary table temps ';
   $ls_sql .= ' select lk_title,lk_link from  lk_t_content ';
   $ls_sql .= " where lk_title like '%".$searchcontent."%' ";
   $res = mysql_query($ls_sql, $dbh);
  
  //得到檢索數(shù)據(jù)的總數(shù)   
   $ls_sql = 'select count(*) as rcnt_con from temps ';
   $res = mysql_query($ls_sql, $dbh);
   $rcon = $row["rcnt_con"];   

   $pages=ceil($rcon / 20); //$pages變量現(xiàn)在總的頁數(shù)   
   if (empty($offset))  {
       $offset=1;   
       $curline = 0;
    } else
      $curline = ($offset - 1) * 20;
   //打印表頭
      print '<tr class="text"> <td width="50%">  <div align="center">';
   if ($offset <> 1) { //如果偏移量是0,不顯示前一頁的鏈接   
     $newoffset=$offset - 1;   
     print "<a href='$
php_SELF?offset=$newoffset'>前一頁</a>";   
   }  else {
     print "前一頁";
     print "   ";
   }
  //顯示所有的頁數(shù)   
  for ($i=1; $i <= $pages; $i++)  {
    $temps = "<a href='".$PHP_SELF.'?offset='.$i."'>".$i."</a>";
    print $temps;   
    print "   ";
  }   
  //檢查是否是最后一頁   
  if ($pages!=0 && $offset!=$pages)  {
     $newoffset=$offset+1;   
     print "<a href='$PHP_SELF?offset=$newoffset'>下一頁</a>";   
  }  else print "下一頁";
  print '</div> </td>';
  print '<td width="50%">  <div align="center">';
  print "當前頁:".$offset." 共".$pages."頁";
  print '</div> </td>';
  print "</table>";

  //顯示查詢信息
  print '<table width="100%" border="1">';
  print '<tr class="text"> ';
  print '<td width="100%">  <div align="center">查詢結果信息</div> </td>';
  print '</tr>';

  $query = "select lk_title,lk_link from temps order by lk_title desc LIMIT ".$curline.",20";
  $res = mysql_query($query, $dbh);  

  $li_num = 0;
  while ($row = mysql_fetch_array($res)) {  
     //采用隔行顯示的方法顯示信息內(nèi)容
     if ($li_number == 0) {
        <tr bgcolor="#dedede">
    $li_number = 1;
     } else {
        <tr bgcolor="#ededed">
    $li_number = 0;
     }
     $tempstr = "<a href='".$row[lk_link]."'>".$row['lk_title']."</a>";
     print '<td width="100%" height="15" class="text">&nbsp;'.$tempstr.'</td>';
     print '</tr>';
  }
  print "</table>";
?>
----------------------------
歡迎訪問:zhangcg.oso.com.cn 
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 奉贤区| 马边| 池州市| 威信县| 鹤峰县| 沐川县| 涡阳县| 龙州县| 开阳县| 隆尧县| 临沭县| 潮安县| 东安县| 丁青县| 曲水县| 渑池县| 册亨县| 石林| 鹤壁市| 分宜县| 诸暨市| 田林县| 汽车| 北票市| 漳平市| 潞西市| 关岭| 泰来县| 庆元县| 南漳县| 广水市| 文成县| 灵丘县| 灵石县| 马边| 万年县| 资阳市| 吉隆县| 吉隆县| 青岛市| 双牌县|