//读取新闻列表信息
var newsUrl = "/delixin/inter/index.php?c=website&a=getNewsList";
var data = ''
$.post( newsUrl, data, function( res ){
if( res.datas ){
var liObj = "";
var fenye =res.datas['show'];
var html = "";
for( i in res.datas ){
html += '<ul style="width:70%;border:0px solid;margin:0 auto;height:10vw;padding:1vw;margin-top:1vw;">'+
'<li>'+
'<div style="border:0px solid;width:30%;float:left;text-align:right;">'+
'<img src="'+res.datas[i]['thum']+'" style="width:68%;height: 160px;margin-right:1vw;">'+
'</div>'+
'<div style="color:#fff;padding:5px 0 0 5px;background:#2B503E;border:0px solid;width:69%;float:right;">'+
'<a href="http://'+window.location.host+'/delixin/website/newsDetail.php?id='+res.datas[i]['id']+'" style="color:#fff;cursor:pointer;"><h4>'+res.datas[i]['title']+'</h4></a>'+
'<div style="margin-top:1vw;">'+res.datas[i]['ctime']+'</div>'+
'<div style="margin-top:1vw;">'+res.datas[i]['content']+'...</div>'+
'<input type="hidden" value="'+res.datas[i]['id']+'" class="id_jzc" />'+
'<div style="margin-top:1vw;padding-bottom:10px;color:#1BB599;"><a href="http://'+window.location.host+'/delixin/website/newsDetail.php?id='+res.datas[i]['id']+'" style="color:#fff;cursor:pointer;">查看详情 >></a></div>'+
'</div>'+
'</li>'+
'</ul>';
}
$("#big_box").html( html );
$(".show_page").html(fenye);
}
else{
alert( '官网新闻数据加载失败' );
}
});<?php
/**
* inter getNews 官网获取新闻数据
*/
defined('IN_IA') or exit('Access Denied');
global $_W, $_GPC;
//获取POST的数据
if($_W['isajax']) {
include IA_ROOT.'/attachment/page.class.php';
//$page = new page();
$showrow = 1; //一页显示的行数
$curpage = empty($_GPC['page']) ? 1 : $_GPC['page']; //当前的页,还应该处理非数字的情况
$url = "?page={page}"; //分页地址,如果有检索条件 ="?page={page}&q=".$_GET['q']
var_dump($_GPC);
$sql = "select * from ims_delixin_article where type=1 order by id desc ";
//$included_files = get_included_files();
//print_r($included_files);
$result= pdo_fetchall($sql);
$num=0;
foreach($result as $value)
{
$num++;
}
$total = $num;
if (!empty($_GPC['page']) && $total != 0 && $curpage > ceil($total / $showrow))
$curpage = ceil($total_rows / $showrow); //当前页数大于最后页数,取最后一页
//var_dump($curpage)
//获取数据
$sql .= " LIMIT " . (($curpage - 1) * $showrow) . ",{$showrow}";
$result=pdo_fetchall($sql);
/********************/
if ($total > $showrow) {//总记录数大于每页显示数,显示分页
$page = new page($total, $showrow, $curpage, $url, 2);
$page_show = $page->myde_write();
}
/********************/
//var_dump($page);
if( $result ){
$data = array();
$data['show']=$page_show;
foreach ($result as $key=>$val ){
//文章标题
$data[$key]['title'] = $val['title'];
$data[$key]['ctime'] = $val['ctime'];
$data[$key]['id'] = $val['id'];
$val['content'] = html_entity_decode( $val['content']);
//过滤html标记(含图片)后的纯文本
$data[$key]['content'] =mb_substr( strip_tags( $val['content'] ),0,70,'utf-8');
//匹配文中的第一张图片
$pattern="/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg]))[\'|\"].*?[\/]?>/";
preg_match_all( $pattern, $val['content'], $matches );//不带引号*/
$data[$key]['thum'] = $matches[1][0]?$matches[1][0]:'';
}
}
if( $data ){
//截取数组的倒序四个
//$return = array_slice( $data, 0, 4 );
returnJson( 0, $data );
}
//获取垃圾分类失败
returnJson( -1, array('status'=>'fail'), 'System is busy' );
}
最佳答案