Skorpius

PDO Display Data from DB on page

Jun 11th, 2022 (edited)
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.35 KB | None | 0 0
  1. <?php
  2.  
  3.     require_once("connect.php);
  4.  
  5.     $stmt = $pdo-prepare(SELECT * FROM tableName");
  6.     $stmt-execute();
  7.  
  8.     while($row = $stmt-fetch())
  9. {
  10.     //DB Fieldnames in square brackets within the single quotes
  11.     $name = $row['name'];
  12.     $quote = $row['fav_quote'];
  13.  
  14.     //Variables here must match above
  15.     echo "<b><i>$quote</i></b><br><p>$name</p>";
  16. }
  17.  
  18.  
  19. ?>
Add Comment
Please, Sign In to add comment