方法1:采用SQL

<ul class="uk-navbar-nav">
                            <?php
                            $topbclassid=0;
                            if($GLOBALS[navclassid]){
                            $temp=explode('|',$class_r[$GLOBALS[navclassid]][featherclass]);
                            $topbclassid=$temp[1]?$temp[1]:$GLOBALS[navclassid];//取得当前栏目的一级栏目ID
                            }
                            echo '<li '.($topbclassid==0?"class='uk-active'":'').'><a href="/">网站首页</a></li>';
                            $sql=$empire->query("select * from {$dbtbpre}enewsclass where bclassid=0  order by myorder limit 12");
                            while($bqr=$empire->fetch($sql))
                            {
                                $sql2=$empire->query("select * from {$dbtbpre}enewsclass where bclassid=$bqr[classid]  order by myorder limit 10");
                                echo '<li'.($topbclassid==$bqr[classid]?" class='uk-active'":'').'><a href="'.sys_ReturnBqClassname($bqr,9).'">'.$bqr['classname'].'</a>';
                                $result=[];
                                while($bqr2=$empire->fetch($sql2))
                                {
                                    $result[]= $bqr2;
                                }

                                while(list($key,$bqr2) = each($result))        //循环获取查询记录
                                {
                                    if($key==0) echo '<div class="uk-navbar-dropdown"><ul class="uk-nav uk-navbar-dropdown-nav">';
                                    echo '<li'.($GLOBALS[navclassid]==$bqr2[classid]?" class='uk-active'":'').'><a href="'.sys_ReturnBqClassname($bqr2,9).'">'.$bqr2['classname'].'</a>';
                                    if($key==(count($result)-1)) echo '</ul></div>';

                                }

                                
                                echo '</li>';
                            }
                            ?>
                        </ul>

方法1:采用缓存数据

/**
 * 二维数组根据某个字段排序
 * @param array $array 要排序的数组
 * @param string $keys   要排序的键字段
 * @param string $sort  排序类型  SORT_ASC     SORT_DESC 
 * @return array 排序后的数组
 */
function user_arraySort($array, $keys, $sort = SORT_DESC) {
    $keysValue = [];
    foreach ($array as $k => $v) {
        $keysValue[$k] = $v[$keys];
    }
    array_multisort($keysValue, $sort, $array);
    return $array;
}
/**
* 从栏目缓存中取得指定栏目 
* @param int $bclassid 父栏目id
* @return array 子栏目数组

*/
function user_getClass($bclassid=0)
{
    global $class_r;
    $result=[];
    foreach($class_r as $key=>$value){
            if($value['bclassid']==$bclassid){
            $result[] = $value;
    }
    }

    return $result;
}

在Pipelines中新建以下类

class PostApiPipeline(object):
    async def process_item(self, item, spider):
        request=scrapy.Request("xxxx/api.php", method="POST", body=json.dumps(dict(item)), headers={'Content-Type': 'application/json'})
        response = await spider.crawler.engine.download(request, spider)
        return item

原查询方式

<?php
require('e/class/connect.php');        //引入数据库配置文件和公共函数文件
require('e/class/db_sql.php');        //引入数据库操作文件
$link=db_connect();                //连接MYSQL
$empire=new mysqlquery();        //声明数据库操作类

$sql=$empire->query("select * from {$dbtbpre}ecms_news order by newstime limit 10");        //查询新闻表最新10条记录
while($r=$empire->fetch($sql))        //循环获取查询记录
{
        echo"标题:".$r['title']."<br>";
}

db_close();                        //关闭MYSQL链接
$empire=null;                        //注消操作类变量
?>

修改后

<?php
require('e/class/connect.php');        //引入数据库配置文件和公共函数文件
require('e/class/db_sql.php');        //引入数据库操作文件
$link=db_connect();                //连接MYSQL
$empire=new mysqlquery();        //声明数据库操作类

$memcache = new Memcache;             //创建一个memcache对象
$memcache->connect('localhost', 11211) or die ("Could not connect"); //连接Memcached服务器

function fetch_memcache($sql,$time=3600){
        global $empire,$memcache,$dbtbpre;
        $key = md5($sql);
        if(!($value =$memcache->get($key))){ //Cache中没有,则从MySQL中查询
         $sql=$empire->query($sql);
         while($r=$empire->fetch($sql)){
          $result[]= $r;
         }
         $value =$result;
         //将Key和Value写入MemCache
         $memcache->set($key,$result,0,time()+$time);
        }
        return $value;
       }

$res=fetch_memcache("select * from {$dbtbpre}ecms_news order by newstime limit 10");        //查询新闻表最新10条记录
while(list($key,$r) = each($res))        //循环获取查询记录
{
        echo"标题:".$r['title']."<br>";
}

db_close();                        //关闭MYSQL链接
$empire=null;                        //注消操作类变量
?>

手机端新建文件

/e/xxx/getHtml.php

<?php
require('../class/connect.php');        //引入数据库配置文件和公共函数文件
require('../class/db_sql.php');        //引入数据库操作文件
require("../class/functions.php");
require("../class/t_functions.php");
require("../data/dbcache/class.php");

require('../class/chtmlfun.php');
require LoadLang('pub/fun.php');

$link=db_connect();                //连接MYSQL
$empire=new mysqlquery();        //声明数据库操作类

$classid=(int)$_GET['classid'];
$id=(int)$_GET['id'];

$r=$empire->fetch1("select * from {$dbtbpre}ecms_".$class_r[$classid][tbname]." where id=$id and classid='$classid'");
if($r){
    GetHtml($r['classid'],$r['id'],$r,1);

}

db_close();                        //关闭MYSQL链接
$empire=null;                        //注消操作类变量
?>

pc端修改文件

在自定义函数文件/e/class/userfun.php中添加

function user_ModFun($mid,$isadd,$isq,$classid,$id,$cs){
    ReadFiletext("http://手机端域名/e/xxx/getHtml.php?id=$id&classid=$classid");
}

pc端模型里添加

后台增加信息后处理函数

DELETE FROM tbname WHERE id IN (
    SELECT id from (
        SELECT id FROM tbname  WHERE oldurl in(
            SELECT oldurl FROM tbname  GROUP BY oldurl HAVING count(oldurl) > 1)
            AND id  not IN(SELECT min(id) FROM tbname  GROUP BY oldurl HAVING count(oldurl) > 1)
    ) as t
);