【发布时间】:2015-02-11 15:12:24
【问题描述】:
我有一个包含三列 date 、 title 、 message 的表格。
我将在每个表格中仅显示日期和标题,并希望在每行之后添加一个单独的按钮,然后我将显示该消息。
我试过了
<?php
echo "<table style='border: solid 3px aqua;'>";
echo "<tr><th>Circular/Notice</th><th>DateGenerated</th></tr>";
class TableRows extends RecursiveIteratorIterator {
function __construct($it) {
parent::__construct($it, self::LEAVES_ONLY);
}
function current() {
return "<td style='width:150px;border:1px solid red;'>" . parent::current(). "</td>";
}
function beginChildren() {
echo "<tr>";
}
function endChildren() {
echo "</tr>" . "\n";
}
}
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "er";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("SELECT title ,DateGenerated FROM messages");
$stmt->execute();
// set the resulting array to associative
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) {
echo $v;
}
}
catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
$conn = null;
echo '<input type ="button" value = "View"/>';
echo "</table>";
?>
我得到的结果只是一个按钮,它也在表格的顶部。
【问题讨论】:
-
我试过了,它在顶部每行显示 2 个按钮。
-
在“每个表”中还是在每行中?
-
每行之后的按钮,当单击任何按钮时,我想显示列消息中的数据