我想在数据库返回的每一行的底部添加一个按钮,但无法理解我将如何执行此操作。该按钮应该是一个简单的“提交”样式按钮。
include("shared.php");
class TableRows extends RecursiveIteratorIterator {
function __construct($it) {
//going through each field - lowest level
parent::__construct($it, self::LEAVES_ONLY);
}
function current() {
return parent::key(). ": " . parent::current(). "</td>" . "<br/>";
}
//goes through, the first row returned
function beginChildren() {
echo " " . "<br/>";
}
//last one
function endChildren() {
echo "</tr>" . "<br/>";
}
}
$database = new PDO("DATABASE CONNECTION");
$database->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$query = $database->prepare("SELECT * FROM Books");
$query->execute();
// set the resulting array to associative
$rows = $query->setFetchMode(PDO::FETCH_ASSOC);
foreach(new TableRows(new RecursiveArrayIterator($query->fetchAll())) as $k=>$v) {
echo $v;
}
答案 0 :(得分:0)
只需在倒数第二行的回声末尾添加按钮:
echo $v . "<button>submit</button>";
答案 1 :(得分:0)
这是你在找什么?
foreach(new TableRows(new RecursiveArrayIterator($query->fetchAll())) as $k=>$v) {
echo $v . '<button type="button">Submit</button>';
}
答案 2 :(得分:0)
添加
echo $v . "<button type='submit' value='Submit'>Submit</button>" in your foreach.