简体   繁体   English

在每个返回行的末尾添加一个Edit.php链接

[英]Adding an Edit.php link to the end of each returned row

I am trying to add a link to the end of each returned result row from the mysql database that will send me to another php page which will allow me to edit the data from the row. 我试图在mysql数据库的每个返回结果行的末尾添加一个链接,该链接会将我发送到另一个php页面,这将允许我编辑该行中的数据。 The problem is I cant find which part of the code I should be adding the link code to so that no matter how many results are returned an edit link will be present at the end of each row. 问题是我找不到应该添加链接代码的代码的哪一部分,因此无论返回多少结果,每行的末尾都会出现一个编辑链接。

Here is the php code I am currently using to retrieve the results. 这是我当前用于检索结果的php代码。

 <?php echo "<table style='border: solid 1px black;'>"; echo "<tr><th>Booking Ref</th><th>First Name</th><th>Last Name</th><th>Contact Number</th><th>Booked Date</th><th>Adults</th><th>Juniors</th><th>Paintballs</th><th>Edit</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 black;'>" . parent::current(). "</td>"; } function beginChildren() { echo "<tr>"; } function endChildren() { echo "</tr>" . "\\n"; } } $servername = "localhost"; $username = "root"; $password = ""; $dbname = "login"; $u_name = $_SESSION['user_name']; try { $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $stmt = $conn->prepare("SELECT booking_id, fname, lname, phone_number, date, adults, juniors, paintballs FROM bookings INNER JOIN users ON users.user_name = bookings.user_name WHERE users.user_name = '" . $u_name . "'"); $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 "</table>"; ?> 

Any help is greatly appreciated, thanks in advance! 非常感谢您的任何帮助,在此先感谢您!

You could place it in endChildren() method. 您可以将其放在endChildren()方法中。 But I'm not sure at all how you can access the row data (you'll obviously need the row id to edit it). 但是我完全不确定如何访问行数据(显然需要行ID进行编辑)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM