在织梦标签中使用SQL实现多个数据的读取方法

内容页中: 
    {dede:field name='mid' runphp=’yes’}
         $aid=@me;                
         $Query = "Select title from `dede_taglist` where mid='".$aid."' limit 0,3";
         $row = $GLOBALS['dsql']->GetOne($Query);
         $GLOBALS['dsql']->Execute();
         @me="";
         while($row =$GLOBALS['dsql']->GetArray()){        
            @me.=$row['title'];
         }
    {/dede:field}

 列表页中: 
    [field:mid runphp="yes"]
         $aid=@me;                
         $Query = "Select title from `dede_taglist` where mid='".$aid."' limit 0,3";
         $row = $GLOBALS['dsql']->GetOne($Query);
         $GLOBALS['dsql']->Execute();
         @me="";
         while($row =$GLOBALS['dsql']->GetArray()){        
            @me.=$row['title'];
         }
     [/field:mid]

单条记录的读取方法:
[field:typeid runphp="yes"]
$aid=@me;
$Query = "Select typename from cxkj_arctype where id='".$aid."'";
$row = $GLOBALS['dsql']->GetOne($Query);br/>@me=$row['typename'];
[/field:typeid]

在模板中嵌入php来读取数据库的方法:

读取单条数据:
$row = $dsql->GetOne("SELECT * FROM dede_archives WHERE id = 7");
print_r($row); //echo $row[title];
?>

读取多条数据:

    $dsql->SetQuery("select * from #@__flinktype");
    $dsql->Execute();
    while($row=$dsql->GetObject())
    {
        echo $row->typename;
    }

?>

转载于:https://blog.51cto.com/14262733/2370557

你可能感兴趣的:(在织梦标签中使用SQL实现多个数据的读取方法)