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

51 lines
1.6KB

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