How JustAnswer Works:

  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.

Ask TheDoctor Your Own Question

TheDoctor, Professional w/Adv. Degree
Category: Homework
Satisfied Customers: 1757
Experience:  M.S. in Internet Information Systems
Type Your Homework Question Here...
TheDoctor is online now
A new question is answered every 9 seconds

For "The Doctor" Extend the recipe application (link to

This answer was rated:

For "The Doctor"

Extend the recipe application (link to files below) to allow users to rate and comment on recipes. Your application should:
Allow each user to post one rating (1–5 scale), with a short comment, for each recipe
Calculate number of ratings for each recipe
Calculate the average rating for each recipe
Display all ratings and comments for a particular recipe
Display the number of ratings and the average rating for each recipe in the recipe directory
Before you write any PHP code, create a table to store the comments and ratings. Based on the requirements above, the table needs fields that identify the user and the recipe, their rating and comment. You should not store the number or average rating for a recipe, but rather calculate these values when necessary. Consider including the date of submission and possibly other fields. Although a user can have only one rating per recipe, each user can rate many recipes, and each recipe may have many ratings. In 1–2 paragraphs, explain how these facts influenced your choice of primary key for this table.

Next, update the PHP application by writing and testing code to:
Allow a logged-in user to rate and comment on a recipe
Allow a user to display the comments on a recipe
Display the number and average rating on the recipe pages
You may find it helpful to structure your code by using PHP functions.

Discuss the design choices you faced and explain the decisions you made (not elaborate). Be sure to address how you ensure that a user cannot rate the same recipe twice and how you handle the average for recipes with no ratings.

Files are located at

Hello again! Thank you for requesting me.

It would be my pleasure to assist you with this. However, such a request is fundamentally high-detail. Any question that requires writing entire scripts of code and creating new database tables is extremely high-detail. A low detail question would be a short answer requiring perhaps 15 - 30 minutes to write up a response. Completing this request will take up to 4 hours of work and the current question value does not justify dedicating that much time.

I will send an under-priced report. You will receive an email with the suggested question value and a link to update the question value.

Thank you
Customer: replied 3 years ago.

no problem

Thank you.

I will contact you once this is complete.
Hello again!

You can download the completed project here:

Inside of newTable.txt you will find the sql for the new table. You must run this sql on your database before any of this will work.

The ratings table represents a many to many relationship between recipes and users. Therefore, the ratings table acts as a join table between the users and the recipes with the user_id and the recipe_id acting as identifying foreign keys between the two tables. These two identifying relationships form a compound primary key. A user and a recipe together identifies a rating (hence an "identifying relationship). This forms a compound primary key on the rating table (user_id, recipe_id).

If no ratings have been submitted for a recipe, no rating is supplied. If there have been ratings, then I simply use the AVG and COUNT aggregate functions in MySQL to get the average rating and number of ratings.

If a user is signed in, they can rate a recipe that they did not enter. A user cannot rate their own recipe. Once a rating has been entered, the user will see it whenever they view the recipe. If the user wishes, he can change his previous rating. However, it is impossible to enter more than one rating per recipe. This is accomplished with the ON DUPLICATE KEY UPDATE functionality in MySQL.

I think you will find that this meets all of the requirements and does so quite nicely. I believe your instructor will enjoy the stars on the view_recipe page.

Let me know if you have any questions. I'm here to help.

Please remember to rate my answer. Thank you so much!
Customer: replied 3 years ago.

Sorry have not had a chance to test yet, but will do so later today and make sure I rate it, thanks for everything.

You are very welcome. I look forward to hearing back from you.
TheDoctor and other Homework Specialists are ready to help you
Customer: replied 3 years ago.
I have downloaded and tried the files, created the table, but I do not see anything about ratings anywhere on the index page, and when I try to load the file view_ratings I get the error:

Fatal error: Uncaught exception 'SmartyException' with message 'Unable to load template file 'view_ratings.tpl'' in C:\xampp\htdocs\Smarty\libs\sysplugins\smarty_internal_templatebase.php:127 Stack trace: #0 C:\xampp\htdocs\Smarty\libs\sysplugins\smarty_internal_templatebase.php(374): Smarty_Internal_TemplateBase->fetch('', NULL, NULL, NULL, true) #1 C:\xampp\htdocs\Unit5\view_ratings.php(53): Smarty_Internal_TemplateBase->display('') #2 {main} thrown in C:\xampp\htdocs\Smarty\libs\sysplugins\smarty_internal_templatebase.php on line 127
I assure you that it all works without issue. It is saying that it cannot find the file view_ratings.tpl

You can see that the view_ratings.tpl is in the files that I sent you.

Do you have time to do a quick remote session? If so, please go to

Once there, select the big orange button to share your screen. You may be asked to install the software. Select yes to everything and allow access to everything. Once it is running, there will be a small dashboard at the top of your screen. Select the URL/address in that dashboard and copy it. Then paste it into this thread so that I can join you.

Thank you
Customer: replied 3 years ago.

You need to spend $3 to view this post. Add Funds to your account and buy credits.

Related Homework Questions