Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function selectAllWithFetch($result){
- // create the table
- print("<table border='4'>");
- // add the rows to the table
- while($row = $result->fetch(PDO::FETCH_ASSOC)) {
- //add a row
- print ("<tr>");
- //print a cell
- print ("<td>$row[date]</td> ");
- print ("<td> $row[time] </td>");
- print ("<td>$row[posted_by] </td>");
- print ("<td> $row[result_information] </td>");
- // print ("<td> $row[username] </td>");
- //close row
- print ("</tr>");
- }
- //close table
- print ("</table");
- function selectWithFetchAll($result) {
- print("<pre>");
- print_r($result->fetchAll(PDO::FETCH_obj));
- print("</pre>");
- }
- /* Main body */
- // print_r(PDO::getAvailableDrivers());
- //connect to the DB
- $dsn = 'mysql:host=localhost;dbname=surgery';
- $user = 'root';
- $password = '';
- try {
- $db = new PDO($dsn, $user, $password);
- } catch (PDOException $e) {
- die('Sorry, database problem');
- }
- $default = "Lina_Carter"; // set this to some username that has tests.
- $username = $_SESSION['username'] ?? $default;
- $queryStr = "SELECT * FROM test_results WHERE username = :username";
- $query = $db->prepare($queryStr);
- $result = $query->execute([':username' => $username]);
- selectWithFetchAll($result);
- }
- ?>
- <a href="myaccount.php"><p>Back to my account</p></a>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement