国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.2KB

  1. <?php
  2. if(!defined('DEDEINC'))
  3. {
  4. exit("Request Error!");
  5. }
  6. /**
  7. * 调用任意表的数据标签
  8. *
  9. * @version $Id: loop.lib.php 1 9:29 2010年7月6日Z tianya $
  10. * @package DedeCMS.Taglib
  11. * @copyright Copyright (c) 2007 - 2020, DesDev, Inc.
  12. * @license http://help.dedecms.com/usersguide/license.html
  13. * @link http://www.dedecms.com
  14. */
  15. /*>>dede>>
  16. <name>万能循环</name>
  17. <type>全局标记</type>
  18. <for>V55,V56,V57</for>
  19. <description>调用任意表的数据标签</description>
  20. <demo>
  21. {dede:loop table='dede_archives' sort='' row='4' if=''}
  22. <a href='[field:arcurl/]'>[field:title/]</a>
  23. {/dede:loop}
  24. </demo>
  25. <attributes>
  26. <iterm>table:查询表名</iterm>
  27. <iterm>sort:用于排序的字段</iterm>
  28. <iterm>row:返回结果的条数</iterm>
  29. <iterm>if:查询的条件</iterm>
  30. </attributes>
  31. >>dede>>*/
  32. require_once(DEDEINC.'/dedevote.class.php');
  33. function lib_loop(&$ctag,&$refObj)
  34. {
  35. global $dsql;
  36. $attlist="table|,tablename|,row|8,sort|,if|,ifcase|,orderway|desc";
  37. FillAttsDefault($ctag->CAttribute->Items,$attlist);
  38. extract($ctag->CAttribute->Items, EXTR_SKIP);
  39. $innertext = trim($ctag->GetInnertext());
  40. $revalue = '';
  41. if(!empty($table)) $tablename = $table;
  42. if($tablename==''||$innertext=='') return '';
  43. if($if!='') $ifcase = $if;
  44. if($sort!='') $sort = " ORDER BY $sort $orderway ";
  45. if($ifcase!='') $ifcase=" WHERE $ifcase ";
  46. $dsql->SetQuery("SELECT * FROM $tablename $ifcase $sort LIMIT 0,$row");
  47. $dsql->Execute();
  48. $ctp = new DedeTagParse();
  49. $ctp->SetNameSpace("field","[","]");
  50. $ctp->LoadSource($innertext);
  51. $GLOBALS['autoindex'] = 0;
  52. while($row = $dsql->GetArray())
  53. {
  54. $GLOBALS['autoindex']++;
  55. foreach($ctp->CTags as $tagid=>$ctag)
  56. {
  57. if($ctag->GetName()=='array')
  58. {
  59. $ctp->Assign($tagid, $row);
  60. }
  61. else
  62. {
  63. if( !empty($row[$ctag->GetName()])) $ctp->Assign($tagid,$row[$ctag->GetName()]);
  64. }
  65. }
  66. $revalue .= $ctp->GetResult();
  67. }
  68. return $revalue;
  69. }