Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
- User Profile 4:02
- Update Password 8:41
- Password Hashing 1 objective
- Creating Helper Functions 5:35
- User Administration Panel 5:18
- Changing User Role 2:40
- Guards and Helpers 5 questions
- Adding Authorization Checks 3:17
- Book Access 3:38
- Update Voting System 3:53
- Next Steps 1:14
- Authorized Login 5 questions
Well done!
You have completed Introduction to User Authentication in PHP!

- 2x 2x
- 1.75x 1.75x
- 1.5x 1.5x
- 1.25x 1.25x
- 1.1x 1.1x
- 1x 1x
- 0.75x 0.75x
- 0.5x 0.5x
Let’s make some updates to our voting system to make sure a user can have only a single vote registered per book. We are going to update our book list as well to show the way the user voted by changing the arrow color.
Other samples for score
Ternary Operator:
echo $book['score']; ?: echo '0';
PHP 7: null coalesce operator
echo $book['score'] :: echo '0';
Breaking Down the Query
Let's break down this query now that it has become more complex.
First we select all columns from the books table and get the sum total of votes for a book and saving that column as score
SELECT books.*, sum(votes.value) as score, "
The main table used in the select.
. " FROM books "
To get the score used in the select, we do a LEFT JOIN of the votes table where the id of the current book equals the book_id's from the votes table.
. " LEFT JOIN votes ON (books.id = votes.book_id) "
Then, we group everything by the book id so there is only 1 row per book
. " GROUP BY books.id "
Finally we order the books by the score DESC so the highest voted book is at the top and the lowest scored book is at the bottom.
. " ORDER BY score DESC";
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up-
Adebayo Ojo
23,661 Points2 Answers
-
David Curran
7,682 Points3 Answers
-
MOD
Jonathan Grieve
Treehouse Moderator 91,254 Points0 Answers
View all discussions for this video
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up