thinkPHP框架下 调用数据库内数据实现在页面

  • Post author:
  • Post category:php


index.php(C:\xampp\htdocs\tp5\application\index\controller)

<?php

namespace app\index\controller;

use think\Db;

use think\Controller;

class Index extends Controller

{


public function index()

{

$data = Db::table(‘date’)->select();//date是我的数据表名

//var_dump($data); 可以查看是否成功获取数据

$this->assign(‘data’, $data);

return view();

}

public function hello($name)

{



return ‘hello’.$name;

}

}

index.html(C:\xampp\htdocs\tp5\application\index\view\index)

<html>

<head>

<title>hello</title>

</head>

<body>

<table border=”1″ width=”800px” align=”center”>



<tr>



<th>ID</th>



<th>AM</th>



<th>PM</th>



</tr>



{volist name=”data” id=”value”}



<tr>



<td>{$value.ID}</td>//ID是我数据表中的栏位名



<td>{$value.AM}</td>



<td>{$value.PM}</td>



</tr>



{/volist}

</table>

</body>

</html>



版权声明:本文为a874909657原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。