discuz代码分析之左连接 t1 left join t2 on t1.id=t2.uid where...

来源:互联网 发布:c#9语言高级编程 pdf 编辑:程序博客网 时间:2024/05/17 23:52
<?php//本地头条$page = isset($_GET['page']) ? (int)$_GET['page'] : 1;if($page < 1) {    $page = 1;}$limit = 20; // 每页显示条数$offset = ($page - 1) * $limit;//$total = DB::result_first('SELECT COUNT(*) FROM '.DB::table('common_block_item')." WHERE bid = ".ODZ_NEWS_BLOCK_ID);$total = DB::result_first('SELECT count(*) FROM '.DB::table('common_block_item')." WHERE bid = ".ODZ_NEWS_BLOCK_ID);$sql = 'SELECT c.id, c.title, c.pic, c.picflag, c.makethumb, c.thumbpath, c.summary, c.fields,f.views  FROM '.DB::table('common_block_item')." as c left join ".DB::table('forum_thread')." as f on c.id = f.tid WHERE c.bid = ".ODZ_NEWS_BLOCK_ID." AND f.displayorder IN(0,1,2,3)  ORDER BY c.displayorder ASC LIMIT $offset, $limit";if(strpos($_G['setting']['attachurl'],'http') !== false){    $img_url = $_G['setting']['attachurl'];}else{    $img_url = $_G['baseurl'].$_G['setting']['attachurl'];}$query = DB::query($sql);$list = array();while ($row = DB::fetch($query)) {    $row['fields'] = unserialize($row['fields']);    if(!$row['fields']['dateline']) {        continue;    }    $arr = array(        'id' => (string)$row['id'],        'title' => (string)odz_format_subject($row['title']),        'replies' => (string)$row['fields']['replies'],        'dateline' => my_date_format($row['fields']['dateline'],'m-d'),        'views'=>(string)$row['views'],    );    // 强制要求生成缩略图    if($row['makethumb']) {        $imgpath = $row['thumbpath'];    } else {        $imgpath = $row['pic'];    }    $arr['thumb'] = $thumburl;    // 截取简介    $arr['summary'] = str_replace(array("\r\n", "\r", "\n"), '', $row['summary']);//    $arr['summary'] = str_replace(" ", '', $arr['summary']);    $arr['summary'] = cutstr($arr['summary'], (count($thumburl) ? 45 : 75));//根据picflag 确认图片url     if($row['picflag'] == 0){        if(strpos($_G['setting']['attachurl'],'http') !== false){            $img_url = $_G['setting']['attachurl'];        }else{            $img_url = $_G['baseurl'].$_G['setting']['attachurl'];        }        $arr['thumb'] = array($img_url.$imgpath);    }elseif($row['picflag'] == 2){        $arr['thumb'] = array($_G['setting']['ftp']['attachurl'].$imgpath);    }else{        $arr['thumb'] = array($img_url.$imgpath);    }    if(strpos($arr['thumb'][0],'nophoto.gif') !== false ){        $arr['thumb'] = array();    }    $list[] = $arr;}$result = array(    'total' => $total['count(*)']?ceil(($total)/20):'0',   // 'perpage' => $limit,   // 'page' => $page,    'list' => $list);?>
0 0
原创粉丝点击