Jump to content
MakeWebGames

Forum Ratings


Recommended Posts

Pretty simple. Allows players to rate other players' posts. I haven't made a staff panel for it, just because its super simple, haha. This mod contains some javascript too! :D

Things to note:

-An individual player may only rate a single post once!

-A player cannot rate their own posts!

The SQL:

You're unable to view this code.

Viewing code within this forum requires registration, you can register here for free.

 

 

forums.php

FIND:

You're unable to view this code.

Viewing code within this forum requires registration, you can register here for free.

 

 

UNDERNEATH PASTE:

You're unable to view this code.

Viewing code within this forum requires registration, you can register here for free.

 

 

FIND NEXT:

You're unable to view this code.

Viewing code within this forum requires registration, you can register here for free.

 

 

UNDER THAT, PASTE:

You're unable to view this code.

Viewing code within this forum requires registration, you can register here for free.

 

 

Now, outside of a function. Paste in:

 

You're unable to view this code.

Viewing code within this forum requires registration, you can register here for free.

 

 

Should work fine. I tested it against basic SQL injections. If you liked it, like my post or thank it. ^^

 

Screenies:

[ATTACH]2158[/ATTACH]

[ATTACH]2159[/ATTACH]

liked.jpg.ae8939ca2d6506df008771aac3702153.jpg

290161339_alreadyrated.jpg.a25a77c4336fa62ce30ea01aa9c86253.jpg

Link to comment
Share on other sites

You could perhaps rather than doing a conditional statement to check if a row already exists if the user has already rated the same, rather than doing that, nest your current conditional statements within a TRY/CATCH? then obviously make your table fields unique (post and user id) then just instantly try and insert? If the row already exists it will fall into the catch statement, thats when you display an error "you've already rated this post".. just a suggestion :}

Link to comment
Share on other sites

A few points

1) Whats the need for the poster field as i cant see where it is used and in theory if you have the post id you can inner join the post to get the poster

2) You have the same query in three places (apart from the pating that could be a variable) you could do something like

You're unable to view this code.

Viewing code within this forum requires registration, you can register here for free.

3) "You have successfully not rated this post!" < may cause confusion

Edited by Dayo
Link to comment
Share on other sites

I agree Dayo, your tables could be much more normalized.. having a table for just posts then having a table for topics for example, suggesstions, question, general discussion etc.. then have another table for ratings, within the ratings you want to put the userID and the ratingID then have another table for ratings, given that id 1 within the ratings table is thanks and 2 is dislike and 3 is like.. quick example:

Post(postID, ownerID*, post, subject, topicID*)

Topics(topicID, topic)

Ratings(ratingID, rating)

post_ratings(ratingID*, postID*, userID*)

user_posts(*postID, comments)

Given that the bold parts are PK's and the asterisks are FK's

etc.. just a suggestion to clean up your tables :)

Link to comment
Share on other sites

You're unable to view this code.

Viewing code within this forum requires registration, you can register here for free.

I dunno, I just think this looks neater. Done on my phone.

I'd say take a DB approach to storing ratings and so on rather than hardcoding stuff, that way it'd make the website a little more dynamic

Link to comment
Share on other sites

Good work [MENTION=70574]TheMasterGeneral[/MENTION]

Whilst there are a few things that can be improved, I feel it's best If I spend less time on explaining how you can improve it, especially since everyone else is giving some very useful information.

I will however thank you for your contribution, it's a good little add-on that makes the standard McCodes forum a bit better.

So good work, keep it up, and have fun!

Link to comment
Share on other sites

Nice, but a couple things to improve on.

You don't need 3 separate queries to get your stats, simply just do it all in one query - http://sqlfiddle.com/#!9/3df4b/1

You're unable to view this code.

Viewing code within this forum requires registration, you can register here for free.

 

---------------

You don't need to query and bring every column back (ie: SELECT *...) it's a waste of overhead. Select what you need.

---------------

You have an } else { to print a blank string. Weird logic...

---------------

You're not ending the headers to make the screen look nice. $h->endpage();

---------------

Perhaps make use of a switch() statement, instead of multiple if/else blocks.

You don't need to put your query inside each if(){} block in the rating snippet. Don't Repeat Yourself.

Link to comment
Share on other sites

1) Whats the need for the poster field

My apologies! That was something else I added into the game. Its used to track how many thanks/likes/dislikes a player has received.

 

You don't need 3 separate queries to get your stats

Yeah. I see the error of my ways. I'm not a(n) 1337 PHP'er/MySQLi'er

 

You're not ending the headers to make the screen look nice. $h->endpage();

From the POV of my WAMP server, $h->endpage(); was already called outside all the functions.

 

You don't need to query and bring every column back

Yeah. Quite stupid of me. Coding at midnight, like a freaking boss. >_>

I'll clean it up a little bit! Stay tuned. ^^

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...