ホームページ  >  に質問  >  本文

两句php语句怎么整合

第一句:

//添加内链
$innerlink = $this->model('innerlink')->all_innerlink();
if($innerlink){
    $last_id = $this->model('innerlink')->get_last_link_id();
    for($i=0;$i<$last_id;$i++)
    {
        $title[$i] = $innerlink[$i]['title'];
        $link[$i] = '<a href='.$innerlink[$i]['description'].' target="_blank">'.$innerlink[$i]['title'].'</a>';
        $article_info['message'] = $this->model('innerlink')->str_replace_once($title[$i],$link[$i],$article_info['message']);
    }
    //$res = $this->model('innerlink')->str_replace_once($title,$link,$article_info['message']);
    //$article_info['message'] = $res;
}

//内链添加结束

第二句

$content = $article_info['message'];
            $res = $this->model('innerlink')->get_category_topic_list(1);
            //print_r($res);
            foreach($res  AS $r) {
                $id = $r['id'];
                $title = $r['title'];
                 if($r['t']=='c'){
                     $content = str_replace($title,"<a  href=\"/explore/category-$id\" >$title</a>",$content);
                 }else{
                     $content = str_replace($title,"<a  href=\"/topic/$title\" >$title</a>",$content);
                 }
            }
            
            $article_info['message'] = $content;
            
            

SQL如下:

    public function get_category_topic_list($type=2)
{
    
    $result_cache_key = 'get_category_tag_list'.$type;
//    AWS_APP::cache()->delete($result_cache_key);
    if ($result = AWS_APP::cache()->get($result_cache_key)){
        return $result;
    }
    switch($type){
        case 1:
            $sql = "SELECT `id` ,`title`,'c' as t  FROM   ".get_table('category');
            break;
        case 2:
            $sql = " SELECT `topic_id` id  ,`topic_title` title,`url_token` url_token,'t' as t  FROM ".get_table('topic');
            break;
        default:
            $sql = "SELECT `id` ,`title`,'c'  as t   FROM ".get_table('category')." union SELECT `topic_id` id  ,`topic_title` title,`url_token` url_token,'t'  as t   FROM ".get_table('topic');    
    }
    
    if ($result = $this->query_all($sql))
    {
        $filter = array('href','ref','ef','f');
        $i=0;
        foreach($result as $r) {
            if(in_array($r['title'],$filter))continue;
            $resulta[$r['title']]['id'] = $r['id'];
            $resulta[$r['title']]['title'] = $r['title'];
            $resulta[$r['title']]['t'] = $r['t'];
            $resulta[$r['url_token']]['url_token'] = $r['url_token'];
        }
        AWS_APP::cache()->set($result_cache_key, $resulta, get_setting('cache_level_high'));
        return $resulta;
    }else{
        return null;
    }
    
}

说明,第一句是通过后台设置关键词,有就自动添加后台的链接,第二句是通过topic来查询,如果存在topic就内链到topic两个代码有冲突,新手不会整合,求带!把他们整合起来,就是如果有后台关键词就链接,有topic就链接

高洛峰高洛峰2772日前311

全員に返信(2)返信します

  • PHPz

    PHPz2017-04-11 09:22:06

    恳请帮忙下,一直找不到怎么处理

    返事
    0
  • PHP中文网

    PHP中文网2017-04-11 09:22:06

    贴出sql, 不要贴代码

    返事
    0
  • キャンセル返事