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

48 lines
1.6KB

  1. <?php
  2. if (!defined('DEDEINC')) exit('dedebiz');
  3. /**
  4. * 调用任意表的数据标签
  5. *
  6. * @version $Id: loop.lib.php 1 9:29 2010年7月6日Z tianya $
  7. * @package DedeBIZ.Taglib
  8. * @copyright Copyright (c) 2022, DedeBIZ.COM
  9. * @license https://www.dedebiz.com/license
  10. * @link https://www.dedebiz.com
  11. */
  12. require_once(DEDEINC.'/dedevote.class.php');
  13. function lib_loop(&$ctag, &$refObj)
  14. {
  15. global $dsql;
  16. $attlist = "table|,tablename|,row|8,sort|,if|,ifcase|,orderway|desc";
  17. FillAttsDefault($ctag->CAttribute->Items, $attlist);
  18. extract($ctag->CAttribute->Items, EXTR_SKIP);
  19. $innertext = trim($ctag->GetInnertext());
  20. $revalue = '';
  21. if (!empty($table)) $tablename = $table;
  22. if ($tablename == '' || $innertext == '') return '';
  23. if ($if != '') $ifcase = $if;
  24. if ($sort != '') $sort = " ORDER BY $sort $orderway ";
  25. if ($ifcase != '') $ifcase = " WHERE $ifcase ";
  26. $dsql->SetQuery("SELECT * FROM $tablename $ifcase $sort LIMIT 0,$row");
  27. $dsql->Execute();
  28. $ctp = new DedeTagParse();
  29. $ctp->SetNameSpace("field", "[", "]");
  30. $ctp->LoadSource($innertext);
  31. $GLOBALS['autoindex'] = 0;
  32. while ($row = $dsql->GetArray()) {
  33. $GLOBALS['autoindex']++;
  34. foreach ($ctp->CTags as $tagid => $ctag) {
  35. if ($ctag->GetName() == 'array') {
  36. $ctp->Assign($tagid, $row);
  37. } else {
  38. if (!empty($row[$ctag->GetName()])) $ctp->Assign($tagid, $row[$ctag->GetName()]);
  39. }
  40. }
  41. $revalue .= $ctp->GetResult();
  42. }
  43. return $revalue;
  44. }