Several websites include direct URLs to access user profiles, and those addresses live alongside a broad set of other URLs. For example, Twitter allows http://twitter.com/mgiglesias to list tweets created by the user mgiglesias
, while an address like http://twitter.com/about would take us to their service description.
This recipe shows us how to create direct URLs for our profile records, allowing the generated URLs to coexist with other application routes we may have.
To go through this recipe we need a sample table to work with. Create a table named profiles
, using the following SQL statement:
CREATE TABLE `profiles`( `id` INT UNSIGNED AUTO_INCREMENT NOT NULL, `username` VARCHAR(255) NOT NULL, `name` VARCHAR(255) NOT NULL, PRIMARY KEY(`id`) );
Add some sample data, using the following SQL statements:
INSERT INTO `profiles`(`id`, `username`, `name`) VALUES (1, 'john', 'John Doe'), (2, 'jane', 'Jane Doe');
Proceed now to create the...