怎么用TP把数据库内容显示到HTML

如题所述

    实例化DB类$db=M('表名');

    查询

    遍历

    分配变量到模板

    搞定

追问

能发发代码吗 参考下

追答<?php

/**
* 属性控制器
*/
class AttrAction extends Action
{

//属性列表视图
public function index(){
//查询数据库
$db = M('attr');
$attr = $db->select();
$this->assign('attr', $attr);
$this->display();
}
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>属性列表视图</title>
<css file="__PUBLIC__/css/public.css"/>
<css file="__PUBLIC__/css/table.css"/>
</head>
<body>
<table class="table">
<tr>
<th>属性名称</th>
<th>属性颜色</th>
<th>操作</th>
</tr>
<foreach name='attr' item="v">
<tr>
<td>{$v.name}</td>
<td bgcolor="{$v.color}">{$v.color}</td>
<td>
<a href="{:U(GROUP_NAME.'/Attr/updAttr',array('id'=>$v['id']))}" class="a-special">修改</a>
<a href="{:U(GROUP_NAME.'/Attr/delAttr',array('id'=>$v['id']))}" class="a-special">删除</a>
</td>
</tr>
</foreach>
<tr><td colspan="3" style="color:red;font-size:30px;font-weight:bold;">该模块已废除</td></tr>
</table>
</body>
</html>

温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答