858Part VCase StudiesOur ratings code will inevitably be (Freelance web design)

858Part VCase StudiesOur ratings code will inevitably be interwoven with the particular content site we choose, butwith minimal changes it ought to work with any content site that has these characteristics. Domain: A quotation siteFor our example domain, we ll create a site that displays amusing quotes from famous andnot-so-famous people. All we want to present to the user on each quotation page is a pithyquote and an attribution. To store these quotations, we ll make a MySQL database for ourentire project and then create a quotation table: create database user_ratings; use user_ratings; create table quotations (ID int primary key auto_increment, quotation varchar(255), attribution varchar(255)); This produces two pieces of text (the quotation itself and an attribution) per row, with anautomatically assigned identification number. Note that we plan for the quotes to be verypithy indeed no more than 255 characters. If you want longer quotes, you should make the quotationfield a larger type, say type text. Possible ratingsWorking from the other end, let s design another table that specifies the rating values thatusers can choose among when rating quotations. This is an equally simple MySQL schema: create table rating_values (ID int primary key auto_increment, rank int not null default 0, rating_text varchar(255)); As always, the IDfield is the unique identifier we rely on. The rankfield we intend for order- ing the rating values if you choose a scale of 1 to 10 style of rating, you want ten rows inthe table, with ranks ranging from 1 to 10. (You could make the IDfield do double duty hereand play the role of the rankfield, if you are careful with order of entry, but this seems likemore trouble than it s worth.) Finally, the textfield contains the explanation of the choicethat will be shown to the voter. While we re at it, let s populate this table with a particular rating scheme. insert into rating_values (rank, rating_text) values (5, 5 - Excellent ); insert into rating_values (rank, rating_text) values (4, 4 - Very good ); insert into rating_values (rank, rating_text) values (3, 3 - Good ); insert into rating_values (rank, rating_text) values (2, 5 - Mediocre ); insert into rating_values (rank, rating_text) values (1, 1 - Poor ); Note that the redundancy of including the rank in the text is necessary only if the rank willnot be displayed along with the text.
Check Tomcat Web Hosting services for best quality webspace to host your web application.

Leave a Reply