What factors should be taken into account when deciding between querying the database or using session variables to store navigation data in a PHP application?

When deciding between querying the database or using session variables to store navigation data in a PHP application, factors to consider include the amount of data being stored, the frequency of access, the need for real-time updates, and the performance implications of each approach.

// Example of using session variables to store navigation data
session_start();

// Set navigation data in session variables
$_SESSION['current_page'] = 'home';
$_SESSION['previous_page'] = 'login';

// Retrieve navigation data from session variables
$current_page = $_SESSION['current_page'];
$previous_page = $_SESSION['previous_page'];