Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP PHP User Authentication Building the Library Accepting the Vote

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

Floated values for voting

I'm pretty sure I've got this voting system to work.

Unlike Alena, I've got multiple book entries in the system already with attempting to add previous books and them not previously appearing on the page. So I can only assume that the fact they switch positions based on the vote values is the default and expected behaviour.

The other thing I noticed is that if I do attempt to change the value, it changes from an integer to a floating point value i.e, "1.0". Is there any reason for this anyone can think of?

You can check out the latest changes to my repo (til the post is resolved) on the s2 branch in my Github Repo. https://github.com/jg-digital-media/php_auth

1 Answer

Benjamin Larson
Benjamin Larson
34,055 Points

I get the same behavior of displaying floating point values. For some reason the schema for the votes table designated the value as a float. So you'll either have to modify the database schema or output it with something like intval().

--Schema pulled from database.db
CREATE TABLE IF NOT EXISTS "votes" (
        `book_id`       INTEGER,
        `user_id`       INTEGER,
        `value` FLOAT NOT NULL
);

how did you manage to change the database file? Whenever I try to open it up it downloads the file or does not let me change anything about it. Can only download the file, nothing else.

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,253 Points

I believe the database was created via the command line. A database file isn't editable but if you can somehow save the data as a .txt or .sql file those are editable.

So... when you're creating a .db you should keep a backup so you can save that backup and upload that as a new version of the database scheme in a .db file.