In what situations would it be more efficient to pass a user ID instead of a name in a URL for sorting and displaying data in PHP?

Passing a user ID instead of a name in a URL for sorting and displaying data in PHP would be more efficient when dealing with large databases or when names are not unique. Using user IDs ensures a unique identifier for each user and can improve performance by directly querying the database with the ID instead of having to search for a name match.

// Example of passing user ID in URL for sorting and displaying data
// URL: example.com/users.php?id=123

// Retrieve user ID from URL parameter
$user_id = $_GET['id'];

// Query database using user ID
$query = "SELECT * FROM users WHERE id = $user_id";
// Execute query and display user data