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

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