Home  >  Article  >  Backend Development  >  Web page images cannot be displayed. How to deal with complex retrieval of data and display in pages

Web page images cannot be displayed. How to deal with complex retrieval of data and display in pages

WBOY
WBOYOriginal
2016-07-29 08:33:21910browse

系统标题:复杂检索数据并分页显示的处理方法
系统功能:利用临时表检索数据库数据,然后分页显示的方法:
处理方法:采用临时表存放数据中间结果,根据中间结果显示数据
          数据的显示采用隔行的方式处理
处理优点:对于复杂的查询,特别是涉及到多表的数据查询,如果直接使用查询条件,系统的
          开销将很大,利用临时表把数据先保存,然后处理。这样对数据库的查询只要开销一次。
使用方法:只要把连接数据库的用户信息和数据表改变即可使用
//连接数据库
$dbh = mysql_connect('localhost:3306','root','');
mysql_select_db('test');
//把数据检索的结果保存到临时表中
$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);
//得到检索数据的总数
$ls_sql = 'select count(*) as rcnt_con from temps ';
$res = mysql_query($ls_sql, $dbh);
$rcon = $row["rcnt_con"];
$pages=ceil($rcon / 20); //$pages变量现在总的页数
if (empty($offset)) {
$offset=1;
$curline = 0;
} else
$curline = ($offset - 1) * 20;
//打印表头
print '

';
   print '';
  print '';
  print "
  
';
   if ($offset <> 1) { //如果偏移量是0,不显示前一页的链接   
     $newoffset=$offset - 1;   
     print "前一页";   
   }  else {
     print "前一页";
     print "   ";
   }
  //显示所有的页数   
  for ($i=1; $i <= $pages; $i++) {
$temps = "".$i."";
    print $temps;   
    print "   ";
  }   
  //检查是否是最后一页   
  if ($pages!=0 && $offset!=$pages)  {
     $newoffset=$offset+1;   
     print "下一页";   
  }  else print "下一页";
  print '
  
';
  print "当前页:".$offset." 共".$pages."页";
  print '
";
  //显示查询信息
  print '';
  print ' ';
  print '';
print '';
$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)) {
                    // Display information content using interlaced display
                                                                                                                 tr bgcolor="#dedede">
           $li_number = 1;                                                                                                                                                      ref=' ".$row[lk_link]."'>".$row['lk_title']."";
  print '';
Print '';
}
print "
  
查询结果信息
'.$tempstr.'
"; -----------------------
Welcome to: zhangcg.oso.com.cn
The above introduces the method of complex retrieval of data and paging display of webpage images that cannot be displayed, including the content of webpage images that cannot be displayed. I hope it will be helpful to friends who are interested in PHP tutorials.


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn