samedi 16 mai 2015

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. 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    
                
        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!




Aucun commentaire:

Enregistrer un commentaire