getMessage(); } //获取表名 $domain = $_SERVER['HTTP_HOST']; $table = 'articles_'.$domain; // 详情页 if(!empty($_GET['id'])) { $data = array('detail' => array(), 'relate1' => array(), 'relate2' => array()); $id = $_GET['id']; //详情页 $sql = "select * from `".$table."` where id =".$id; $sth = $dbh->query($sql); $data['detail'] = $sth->fetch(PDO::FETCH_ASSOC); //相关推荐 //热门文章 //包含文件 include_once('detail.php'); } else { $data = array('page'=>1, 'lastPage' => 1,'count' => 0, 'list' => array(), 'relate1' => array(), 'relate2' => array()); //列表页 //数据数量 $sql = "select count(*) as count from `".$table."`"; $sth = $dbh->query($sql); $data['count'] = $sth->fetch(PDO::FETCH_ASSOC)['count']; $data['lastPage'] = ceil($data['count'] / 10); //列表数据 if(empty($_GET['page'])) { $data['page'] = 1; } else { $data['page'] = $_GET['page']; } $limit = 10; $limitStart = 10 * ($data['page'] - 1); $sql = "select id,title,summary,img,publish_time from `".$table."`order by id desc limit ".$limitStart.",".$limit; $sth = $dbh->query($sql); $data['list'] = $sth->fetchAll(PDO::FETCH_ASSOC); // 热门文章 $num = intval((preg_replace('|[a-zA-Z/]+|','',md5(date("Y-m-d"))))); $id =$num%intval(date("md")); $sql = "select id,title,summary,img,publish_time from `".$table."`where id > ".$id." limit ".$limit; $sth = $dbh->query($sql); $data['hot'] = $sth->fetchAll(PDO::FETCH_ASSOC); if(count($data['hot']) < 5){ $sql = "select id,title,summary,img,publish_time from `".$table."`where id < ".$id." limit ".$limit; $sth = $dbh->query($sql); $data['hot'] = $sth->fetchAll(PDO::FETCH_ASSOC); } // 最新文章 //包含文件 include_once('list.php'); }