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
Keywords
Related Questions
- What is the purpose of using "include" in PHP and how does it affect variable scope?
- How can one handle undefined index errors in PHP when using $_GET?
- In what scenarios is it necessary to encode text to quoted-printable when using the mail() function in PHP, considering the 8-bit clean nature of modern applications and operating systems?