!
也想出现在这里? 联系我们
广告位

dede:sql实现分页,织梦sql实现分页的办法

文章介绍

思路是把dede:list标签进行改造, 列表页专用标签的工作原理大致是先通过栏目变量id获取到对应的数据源再呈现到页面上来,那么 就可以让它不仅仅通过栏目变量id还可以通过指定的sql语句来获取数据源 可以另外嵌入一个类! & y似{dede:listsql sql='se, F Z p k V \ Olect * from wp_posts' pagesize='10'}的标签来使用。

打开include/arc.m r | g ? H g :listview.class.php这个文件

找到:

if ( ! isR [ 9 ^ j_object ( $ctag ) ) { $ctag = $this -> dtp -> GetTag ( "list" ); }

这一段,在其后添加如下代码

if(!is_object($ctag))
{
$ctag = $this->dtp-J I r \ = J>GetTag("listsql")m # q b = c Q;
if (is_object($ctag))
{
$cquery = $ctag->GetAtt("sql");
$cquery = pr; O Keg_replace("/SELECT(.*?)FROM/is", " SELECT count(*) as dd FROM ", $cquery);
$cquery# + E [ b W 3 $ = preg_replace("/ORDER(.*?)SC/is",L x 9 "", $cquery);
$row = $this->dsql->GetOne($cqup : Bery);
if(is_aR $ M {rray($N 4 | U X E E Xrow))
{
$this->TotalResult = $row['dd'];
}
else
{
$this->Tot5 n G a +alResult = 0;
}
}
}
然后找到:
if($ctag->GetName()=="list")
{
$limitstart = ($this->PageNo-1) * $this->PageS} S g q x M 4 +ize;
$row = $this->PageSize;
if(~ ^ O R u U - ttrim($ctag->GetI3 S | t + 0 * H qnnerText())=="")
{
$InnerText = GetSysTemplets("list_fI G o 8 J MullR = w = l : H slist.htm");
}
e/ X k U Else
{
$InnerText = trim($ctag->GetInnerText());
}
$this->dtp->Assign($tagid,
$this->GetArcList(
$lK t B e z \ B :imitstart,
$row,
$ctagH a = _ P 5->GetAtt("col"),
$ctag->GetAtt("titlelen"),
$ctag->GetAtt("infolen"),
$ctag->GetAtt("imgwidth"),
$ctag->GetAtt(d J 9"imgheight"),
$ctag->GetAtt("listtype"),
$ctaS h t F n D ng->GetAtt("orderby"),
$InnerText,
$ctag->GetAtt() 2 ^ + A"tablewidth"),
$ismake,
$cU j \ ktag->Gem } #tAtt("orderway")
)
);
}
这一段,在其后添加如下代码:
else if($ctag->GetName()=="lisw \ m Z 7tsql")
{
$limitstart = ($th) L 2 lis->PageNo-1) * $this->PageSize;
$row = $this->PageSize;
if(trim($ctag->GetInnerText())=="")
{
$InnerText = GetSysTemplets("list_fulllist.htm");
}
else
{
$InnerText = trim($ctag->GetInnerText());
}
$this->dtp->Assign($tagi^ [ D $ H Gd,
$this->GetSqlList(
$limitstart,
$\ v ; 5 g / Wrx r 7ow,
$ctaT W Y Q G / _g->GetAtt("sql"),
$C q h % 6 f r :In{ c V q @ % SnerText
)
);
}
最后找到function GetArcList这个方法,在其\ x /后添加一个可以通过传入B J w rsql参i X I数获取指定数据源的方法,E M H \ x z + X代码如下:

function GetSqlLisj O ^ ; G ~ 1 $t($limitstart = 0, $row = 10, $sql = '', $innertext){

global $cfg_list_son;
$innertext = trim($innertext);

if ($innertl 5 @ u ( c z m oext == '') {
$innertext = GetSysTemplets('list_fulK ^ s y O ;llist.htm');
}
//处理SQL语句
$limitStr@ q Q 3 y D = " LIMIT {$limitstart},{$row}";

$this->dsql->SetQuery($sql . $limitStr);
$this->dsql->Execute('al');
$t2 = Exe, & & ; 0 7cTime();

//echo $t2-$t1;
$sqllist = '';
$this->dtp2->LoadSource(G 3 ! 1 q$innertext);
$GLOBALS['autoindex'] =K C ! 0;

//获取字段
while($row = $tha c ois->dsql->GetArray("al")) {

$GLOBALS['autoindex']++;

if(is_array($this->dtp2->CTags))
{
forea\ e _ ; } Dch($this->dtY : lp2->CTags as $k=>$ctag)
{
i- ! x $ D gf($ctag->GetName()==) v v Q X M , O'array')
{
//传递整个数组,在runphp模式中有特殊作用
$this->dtp2->Assign($k,$row);
}
elsh U + $ ) 4e
{
if(isset($row_ & U K [[$ctag->GetName()]))
{
$this->dtpG x a2->Assign($k,$row[$ctag->GetName()]);
}
else
{
$this->dtp2->Assign($k,'');
}
}
}
}

$sqllist .= $this->dtp2->GetResult();

}//while

$t3 = ExecTime();
//echo ($t3-$t2);
$this->dsql->FreeResult('al');

return $sqllist;
}
总共就添加三段代码,调用范例:
{dede:listsql sql='select ID,post_title from wp_po` k U ; nsts' pagesi% U : % ~ze='10'}
<li>&l8 G J ( U = )t;a href="http://A ] Z [ } V Ywww.weimahe.com/[field:ID /].html">[field:post_title /]<` . S Q 6 x c @ V/a></li>
{/dede:listsql}
&l1 P = , 7 ( 2 nt;!--分页-->
{dede:pagelist listsize='2' listitem='inW { b : N 6 + Zdex pre pageno next end '/}

{dede:sql}和{dede:listst + v 7 N jql}的文章链接地址<a href="https://www.dede58.com/a/dedejq/[field:id runphp='yes'] $id=@me;@me='( m R r O % ( W';$url=Ge( P ` 2 B K - ~tOU q 1 d { Q @ NneArchive($id);@me=$url['arcurl'];[/field:id]">

给TA打赏
共{{data.count}}人
人已打赏
CMS教程

DEDE获得顶级栏目名称的方法

2022-2-11 2:59:58

CMS教程

DEDECMS安全设置怎样做,您就不会说它不安全了

2022-2-12 2:59:42

下载说明

  • 1、微码盒所提供的压缩包若无特别说明,解压密码均为weimahe.com
  • 2、下载后文件若为压缩包格式,请安装7Z软件或者其它压缩软件进行解压;
  • 3、文件比较大的时候,建议使用下载工具进行下载,浏览器下载有时候会自动中断,导致下载错误;
  • 4、资源可能会由于内容问题被和谐,导致下载链接不可用,遇到此问题,请到文章页面进行反馈,以便微码盒及时进行更新;
  • 5、其他下载问题请自行搜索教程,这里不一一讲解。

站长声明

本站大部分下载资源收集于网络,只做学习和交流使用,版权归原作者所有;若为付费资源,请在下载后24小时之内自觉删除;若作商业用途,请到原网站购买;由于未及时购买和付费发生的侵权行为,与本站无关。本站发布的内容若侵犯到您的权益,请联系本站删除,我们将及时处理!
0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索