Advertisement
Skorpius

Database Query Function (Users Online)

Jun 22nd, 2022
1,316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.64 KB | None | 0 0
  1.     //Query looks at table for users with Yes in the logged_in column
  2.     //which means they are logged in and gives the usernames.
  3.  
  4.     require("connect/connect.php");
  5.  
  6.     //Function to get all usernames that are online
  7.     function usersOnline($pdo){
  8.         $online = 'Yes';
  9.  
  10.         $query = ("SELECT username FROM users WHERE logged_in = ?");
  11.  
  12.         $stmt1 = $pdo->prepare($query);
  13.  
  14.         $stmt1->bindParam(1,$online);
  15.         $stmt1->execute();
  16.  
  17.         $rows = $stmt1->fetchAll(PDO::FETCH_ASSOC);
  18.        
  19.         foreach($rows as $val){echo "{$val['username']}". " ";}
  20.     }
  21.  
  22. //To call the function - <?php usersOnline($pdo); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement