Advertisement
Skorpius

PDO Display Data Prepared Statement with Condition

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