国内流行的内容管理系统(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.

56 lines
1.7KB

  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) 2020, DedeBIZ.COM
  12. * @license https://www.dedebiz.com/license
  13. * @link https://www.dedebiz.com
  14. */
  15. require_once(DEDEINC.'/dedevote.class.php');
  16. function lib_loop(&$ctag,&$refObj)
  17. {
  18. global $dsql;
  19. $attlist="table|,tablename|,row|8,sort|,if|,ifcase|,orderway|desc";
  20. FillAttsDefault($ctag->CAttribute->Items,$attlist);
  21. extract($ctag->CAttribute->Items, EXTR_SKIP);
  22. $innertext = trim($ctag->GetInnertext());
  23. $revalue = '';
  24. if(!empty($table)) $tablename = $table;
  25. if($tablename==''||$innertext=='') return '';
  26. if($if!='') $ifcase = $if;
  27. if($sort!='') $sort = " ORDER BY $sort $orderway ";
  28. if($ifcase!='') $ifcase=" WHERE $ifcase ";
  29. $dsql->SetQuery("SELECT * FROM $tablename $ifcase $sort LIMIT 0,$row");
  30. $dsql->Execute();
  31. $ctp = new DedeTagParse();
  32. $ctp->SetNameSpace("field","[","]");
  33. $ctp->LoadSource($innertext);
  34. $GLOBALS['autoindex'] = 0;
  35. while($row = $dsql->GetArray())
  36. {
  37. $GLOBALS['autoindex']++;
  38. foreach($ctp->CTags as $tagid=>$ctag)
  39. {
  40. if($ctag->GetName()=='array')
  41. {
  42. $ctp->Assign($tagid, $row);
  43. }
  44. else
  45. {
  46. if( !empty($row[$ctag->GetName()])) $ctp->Assign($tagid,$row[$ctag->GetName()]);
  47. }
  48. }
  49. $revalue .= $ctp->GetResult();
  50. }
  51. return $revalue;
  52. }