发布时间:2024-03-28 17:35:32
您提到的“织梦”和“dede:sql”可能指的是织梦CMS(Dreamweaver)、以及该系统中的SQL相关操作。如果您需要在织梦CMS中实现列表页分页的教程方法
例如:在模板标签上实现如下功能
{dede:listsql sql='SELECT * FROM dede_aq_redirect ORDER BY id' return='items' pagesize="2" } [field:title/] {/dede:listsql}
实现方案如下 打开include/arc.listview.class.php 找到 :
在该文件找到如下代码:
if(!is_object($ctag)) { $ctag = $this->dtp->GetTag("list"); }
在下面增加以下代码:
if(!is_object($ctag)) { $ctag = $this->dtp->GetTag("listsql"); if(is_object($ctag)) { $cquery = $ctag->GetAtt("sql"); //$cquery = str_replace('~reid~',$this->ReID,$cquery); 这是另一个客户要求的获取url第2个参数才加的。 $cquery = preg_replace("/SELECT(.*?)FROM/is", " SELECT count(*) as dd FROM ", $cquery); $cquery = preg_replace("/ORDER(.*?)SC/is", "", $cquery); $row = $this->dsql->GetOne($cquery); if(is_array($row)) { $this->TotalResult = $row['dd']; } else { $this->TotalResult = 0; } } }
2. 该文件找到以下代码:
else if($ctag->GetName()=="pagelist")
在上面增加以下代码
else if($ctag->GetName()=="listsql") { $limitstart = ($this->PageNo-1) * $this->PageSize; $row = $this->PageSize; if(trim($ctag->GetInnerText())=="") { $InnerText = GetSysTemplets("list_fulllist.htm"); } else { $InnerText = trim($ctag->GetInnerText()); } $this->dtp->Assign($tagid, $this->GetSqlList( $limitstart, $row, $ctag->GetAtt("sql"), $InnerText )); }
3. 该文件找到以下代码:
function GetPageListST(
在它上面加入以下代码
function GetSqlList($limitstart = 0, $row = 10, $sql = '', $innertext) { global $cfg_list_son; $innertext = trim($innertext); if ($innertext == '') { $innertext = GetSysTemplets('list_fulllist.htm'); } //处理SQL语句 $limitStr = " LIMIT {$limitstart},{$row}"; $sql = str_replace('~reid~',$this->ReID,$sql); $this->dsql->SetQuery($sql . $limitStr); $this->dsql->Execute('al'); $t2 = ExecTime(); //echo $t2-$t1; $sqllist = ''; $this->dtp2->LoadSource($innertext); $GLOBALS['autoindex'] = 0; //获取字段 while($row = $this->dsql->GetArray("al")) { $GLOBALS['autoindex']++; if(is_array($this->dtp2->CTags)) { foreach($this->dtp2->CTags as $k=>$ctag) { if($ctag->GetName()=='array') { //传递整个数组,在runphp模式中有特殊作用 $this->dtp2->Assign($k,$row); } else { if(isset($row[$ctag->GetName()])) { $this->dtp2->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; }
修改完成,可以试试模板上自定义标签功能