搜外网>搜外问答>问答页面

求查询数据库循环输出的优化

<p>求查询数据库然后循环输出的优化方法,有大神请帮忙修改一下贴出来,谢谢。</p><p>需要优化部分的代码是,这个是查询杰奇小说数据列表,才几千条数据,但是反应很慢,差不多10-30S才能出现页面:</p><p>if ($catid>"11" and $catid>"0")
</p><p>{$catid=0;}
</p><p>$m="18";//每页显示的记录数
</p><p>if ($catid<"11" and $catid>"0")
</p><p>{
</p><p>$where="WHERE chapters>='2' and sortid='$catid'";
</p><p>}else{
</p><p>$where="WHERE chapters>='2'";
</p><p>}
</p><p>$numsql="select  from jieqi_article_article $where";
</p><p>$numery = mysql_query($numsql);
</p><p>$lognum = mysql_num_rows($numery);//总记录数
</p><p>$zy = (int)(($lognum-1)/$m)+1;//总页数
</p><p>isset($_GET['page'])?$page=$_GET['page']:$page="1";//当前页数
</p><p>isset($_GET['cat'])?$catid=$_GET['cat']:$catid="0";//当前分类数
</p><p>$one = (int)($page-1)
$m;//当前页的首条记录
</p><p>if ($catid<"11" and $catid>"0"){
</p><p>$sql="select  from jieqi_article_article WHERE chapters>='2' and sortid='$catid' order by lastupdate desc limit $one,$m";
</p><p>}else{
</p><p>$sql="select 
 from jieqi_article_article WHERE chapters>='2' order by lastupdate desc limit $one,$m";
</p><p>}
</p><p>$result = mysql_query($sql);</p><p><br></p><p>在where循环里我用了以下代码:</p><p> while($list=mysql_fetch_array($result))  </p><p>{</p><p>$s = <<<heredoc
</p><p>s.jpg
</p><p>heredoc;
</p><p>$id = <<<heredoc
</p><p>$list[articleid]
</p><p>heredoc;
</p><p>$book_img_z=intval($id/1000);
</p><p>$imgurl = <<<heredoc
</p><p>$imgfromurl/$book_img_z/$id/$id$s
</p><p>heredoc;
</p><p>$file = "$imgurl";
</p><p>$fileExists = @file_get_contents($file,null,null,-1,1) ? true : false;
</p><p>if($fileExists){
</p><p>}else{
</p><p>$imgurl = <<<heredoc
</p><p>$weburl/img/no.jpg
</p><p>heredoc;
</p><p>}
</p><p>if($wjt==0){
</p><p>$bookurl = <<<heredoc
</p><p>$weburl/book.php?id=$id
</p><p>heredoc;
</p><p>}else{
</p><p>$bookurl = <<<heredoc
</p><p>$weburl/book/$id.html
</p><p>heredoc;
</p><p>}</p><p>echo '</p><p><br></p><p>......................</p><p>';</p><p>}</p>

追加问题
    1 人参与回答
SEO培训招生中
189