【发布时间】:2015-11-29 23:23:33
【问题描述】:
我可以从 JSON 输出成功显示引导表,但是我不知道如何在最后一列上填充一个按钮以显示在每一行中
<table class = "table table-hovergrey" data-search="true" data-toggle="table" data-url="php/data.php" data-height="auto">
<thead>
<tr>
<th data-field="ID">ID</th>
<th data-field="Name">Name</th>
<th data-field="Age">Age</th>
</tr>
</thead>
</table>
PHP 代码
<?php
// DB Credentials goes here
$db_name = 'dbName';
$hostname = 'hostname';
$username = 'username';
$password = 'password';
// connect to the database
$dbh = new PDO("mysql:host=$hostname;dbname=$db_name", $username, $password);
// a query get all the records from the users table
$sql = 'select ID,Name,Age from PEOPLE ';
// use prepared statements, even if not strictly required is good practice
$stmt = $dbh->prepare( $sql );
// execute the query
$stmt->execute();
// fetch the results into an array
$result = $stmt->fetchAll( PDO::FETCH_ASSOC );
// convert to json
$json = json_encode( $result );
// echo the json string
echo $json;
?>
【问题讨论】:
-
表上的数据是从 PHP 文件中填充的,我从 SQL 数据库中获取数据并将结果存储在 JSON 输出中
标签: php sql twitter-bootstrap-3 html-table