dimanche 5 décembre 2021

Displaying mysql table data with an added column for a checkbox

So I have this function that displays all the data in my mysql table.

function maindbdisplay(){
    echo "<table style='border: solid 1px black;'>";
    echo "<tr><th>DBid</th><th>Firstname</th><th>Lastname</th><th>email</th><th>NFCid</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";
        }
    }

    global $conn;
    $stmt = $conn->prepare("SELECT * from registered;");
    $stmt->execute();

    // set the resulting array to associative
    $result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
    foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) {
       //$v is table data with headers, $k is table headers only  
       //this displays all headers first, then each loop displays values under the next header   
       echo $v;
    }

    global $sql;
    $sql="select * from registered;"; $conn->exec($sql);
}

Now, I would like to have an extra column at the beginning of the table where there is a checkbox for each data entry, so I can select entries and for example delete them. I did not find any plausible answers while searching for a solution.




Aucun commentaire:

Enregistrer un commentaire