我试图在mysql数据库的每个返回结果行的末尾添加一个链接,该链接会将我发送到另一个php页面,这将允许我编辑该行中的数据。 问题是我找不到应该添加链接代码的代码的哪一部分,因此无论返回多少结果,每行的末尾都会出现一个编辑链接。

这是我当前用于检索结果的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>"; ?> 

非常感谢您的任何帮助,在此先感谢您!

===============>>#1 票数:0 已采纳

您可以将其放在endChildren()方法中。 但是我完全不确定如何访问行数据(显然需要行ID进行编辑)。

  ask by WJLuppy translate from so

未解决问题?本站智能推荐: