I'm new here, but I love the site. I checked through the other similar questions, but I didn't see what I'm looking for.
I'm a musician, and I've been doing a "song of the day" thing for a while where I write a little song every day. I want to post the songs as <div>
s inside <li>
. In the divs, I just want a simple mp3 player and a "like" or "dislike" button. The user can vote and the song will move up or down the <li>
based on the number of votes.
I want to keep this simple with the math-just subtracting the dislikes from the likes in the <li>
array and ordering them from highest to lowest.
It'd be good to have a simple cookie system in place to at least keep someone from voting a lot all in one sitting, but I'm not too concerned about it.
I've been looking for a simple PHP or Javascript tutorial on this. Can anyone point me in the right directions? Thanks!
You're going to need a central location to store this song information, mainly the votes, but you might as well through the other song information (like title, path to music file, etc) in there as well. I suggest a simple MySQL table as follows
I used the following HTML structure:
And a touch of CSS
Here's the JavaScript, using jQuery
And some stub PHP for
vote.php
:I'll leave the PHP for you to fill in. Shouldn't be too much of a stretch. Let me know if you have any questions.
Yeah, a MySQL table seems critical, to maintain the votes as you collect them. Then a function to return or output the
<li>
's in sorted order, as you are constructing the page. If Justin doesn't come back with more, I will add more later.