系統(tǒng)功能:利用臨時表檢索數(shù)據(jù)庫數(shù)據(jù),然后分頁顯示的方法:
處理方法:采用臨時表存放數(shù)據(jù)中間結果,根據(jù)中間結果顯示數(shù)據(jù)
數(shù)據(jù)的顯示采用隔行的方式處理
處理優(yōu)點:對 " /> av中文字幕在线观看第一页 ,久久频这里精品99香蕉,久青草国产97香蕉在线视频

色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

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

系統(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 '<table width="100%" border="0">';
   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"> '.$tempstr.'</td>';
     print '</tr>';
  }
  print "</table>";
?>
----------------------------
歡迎訪問:zhangcg.oso.com.cn 

php技術復雜檢索數(shù)據(jù)并分頁顯示的處理方法,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 鹤壁市| 中牟县| 巴东县| 宜宾县| 吉隆县| 安吉县| 北宁市| 宁化县| 潞城市| 安国市| 宣城市| 苏尼特右旗| 巧家县| 青州市| 富平县| 庐江县| 广元市| 鄂伦春自治旗| 南川市| 辽宁省| 永定县| 陕西省| 万州区| 澄城县| 花莲县| 永济市| 龙江县| 南京市| 洞口县| 临江市| 阿尔山市| 德安县| 大宁县| 河源市| 十堰市| 青阳县| 永福县| 洛扎县| 宁安市| 成都市| 拉萨市|